[Haskell-cafe] need help with understanding expression

Albert Y. C. Lai trebla at vex.net
Sun Nov 18 02:57:19 CET 2012


On 12-11-17 02:19 AM, damodar kulkarni wrote:
> Let's see tthis:
> Prelude> :t 3 "a"
> 3 "a" :: (Num ([Char] -> t)) => t
>
> No complaint from GHC; but now see this:
>
> Prelude> :t  "a" 3
>
> <interactive>:1:0:
>      Couldn't match expected type `t1 -> t'
>             against inferred type `[Char]'
>      In the expression: "a" 3
>
> Why does it not fail for  (:t 3 "a") but does fail for (:t  "a" 3)?

3 is polymorphic, "a" is monomorphic (exactly [Char]).

To make "a" polymorphic, turn on OverloadedStrings:

:set -XOverloadedStrings
:type "a"

"a" :: Data.String.IsString a => a

:type "a" 3

"a" 3 :: (Num a, Data.String.IsString (a -> t)) => t

Success!

This is clearly depravity.



More information about the Haskell-Cafe mailing list