
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

On Thu, Jan 19, 2012 at 10:55 PM, Kazu Yamamoto
Hello,
I met strange behavior of let in ghci 7.0.4. The following works well.
You're running into the monomorphism restriction: http://www.haskell.org/haskellwiki/Monomorphism_restriction
let chooseMax = maximumBy compFst
If you re-define this to be:
let chooseMax x = maximumBy compFst x
you'll get around it in the easiest way. You can also turn off the restriction at the command-line with the argument '-XNoMonomorphismRestriction', I think. Antoine

Antoine,
You're running into the monomorphism restriction: http://www.haskell.org/haskellwiki/Monomorphism_restriction
Oh. Thanks.
You can also turn off the restriction at the command-line with the argument '-XNoMonomorphismRestriction', I think.
I will use "ghci -XNoMonomorphismRestriction" in my tutorial. Thank you again. --Kazu

On Thu, Jan 19, 2012 at 11:10:09PM -0600, Antoine Latter wrote:
On Thu, Jan 19, 2012 at 10:55 PM, Kazu Yamamoto
wrote: Hello,
I met strange behavior of let in ghci 7.0.4. The following works well.
You're running into the monomorphism restriction: http://www.haskell.org/haskellwiki/Monomorphism_restriction
To be more precise, it's the monomorphism restriction combined with ghci's extended type-defaulting rules: http://www.haskell.org/ghc/docs/7.2.2/html/users_guide/interactive-evaluatio... -Brent
participants (3)
-
Antoine Latter
-
Brent Yorgey
-
Kazu Yamamoto