---
title: "均值(haskell)"
author: "jedy"
date: "2005-11-30T01:17:00Z"
tags: []
slug: "haskell"
draft: false
lastmod: "2005-11-30T01:17:00Z"
id: 304780
url: "https://jedy.iteye.com/blog/304780"
---

想写一个求均值的函数。  
写成

mean x = sum(x) / length(x)总是类型不对，double/int除不了。

没办法，还没有看到怎么转换类型，只有重写了一个length。

```

mean x = sum(x) / len(x)
  where len [] = 0.0
        len x = 1.0 + len (tail x)
```