开发者

Why is GHCi typing this statement oddly?

In answering a question on stackoverflow, I noticed that GHCi (interactive) is开发者_StackOverflow assigning a too-restrictive type in a let statement. Namely, given the code,

import Control.Arrow
f = maximum &&& id >>> fst &&& (\(m,l) -> length $ filter (==m) l)

(as on my answer to https://stackoverflow.com/questions/6281813/maximum-of-list-and-count-of-repeat-maximum-number/6283594#6283594), if one inserts a "let" before f and enters this in ghci, it gives the following type information

Prelude Control.Arrow> :t f
f :: [()] -> ((), Int)

whereas just asking for the type of the expression gives the correct result, namely Ord a => [a] -> (a, Int). I'm using ghc 7.0.3.


See the extended defaulting rules used in GHCi for an explanation of where the () is coming from.

As for why the defaulting occurs in this case, compare the following:

> let f x = maximum &&& id >>> fst &&& (\(m,l) -> length $ filter (==m) l) $ x
> :t f
f :: (Ord a) => [a] -> (a, Int)

I assume this has something to do with bindings being monomorphic, but I'm not certain of the details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜