strange behavior of let in ghci

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Fri Jan 20 05:55:56 CET 2012


Hello,

I met strange behavior of let in ghci 7.0.4. The following works well.

> :m Data.List
> let compFst (n1,s1) (n2,s2) = compare n1 n2
> maximumBy compFst [(1, "boo"), (3, "foo"), (2, "woo")]
(3,"foo")

But if I bind "maximumBy compFst" to "chooseMax" with "let", it causes
error:

> let chooseMax = maximumBy compFst
> chooseMax [(1,"boo"),(3,"foo"),(2,"woo")]
<interactive>:1:33:
    No instance for (Num ())
      arising from the literal `2'
    Possible fix: add an instance declaration for (Num ())
    In the expression: 2
    In the expression: (2, "woo")
    In the first argument of `chooseMax', namely
      `[(1, "boo"), (3, "foo"), (2, "woo")]'

It's very strange to me. Why does this happen? 

":t" says:

> :t maximumBy compFst
maximumBy compFst :: Ord a => [(a, t)] -> (a, t)
> :t chooseMax 
chooseMax :: [((), t)] -> ((), t)

I'm writing a tutorial of Haskell and I would like to define chooseMax
in ghci with "let" without specifying its signature.

--Kazu



More information about the Glasgow-haskell-users mailing list