[Haskell-cafe] a code that cannot compile with or without NoMonomorphismRestriction
Ketil Malde
ketil at malde.org
Thu Mar 29 12:27:04 CEST 2012
Ting Lei <tinlyx at hotmail.com> writes:
> (f1, f2) =
> let commond_definitions = undefined in
> let f1 = id.show
> f2 x = (< x)
> in
> (f1, f2)
I think the type signatures should be:
f1 :: Show a => a -> String
and
f2 :: Ord b => b -> b -> Bool
When I define these separately, this works:
f1 :: Show a => a -> String
f1 = id . show
f2 :: Ord b => b -> b -> Bool
f2 = flip (<)
But when I define them as a pair
f1 :: Show a => a -> String
f2 :: Ord b => b -> b -> Bool
(f1,f2) = (id . show, flip (<))
I get an error message:
Line 9: 1 error(s), 0 warning(s)
Couldn't match expected type `forall a. Show a => a -> String'
with actual type `a -> String'
When checking that `f1'
has the specified type `forall a1. Show a1 => a1 -> String'
Defining the pair at once works:
p :: (Show a, Ord b) => (a -> String, b -> b -> Bool)
p = (id . show, flip (<))
I guess that didn't help a lot, somebody with deeper GHC-fu than me will
have to step in.
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list