[Haskell-beginners] Is this a GHC bug? Problem inferring type
Michael Peternell
michael.peternell at gmx.at
Sat Jun 8 20:54:44 CEST 2013
in my opinion this is a bug of ghc. maybe the implementation works exactly as it should, according to the specification: then it's a bug in the specification.
Show a => a -> a -> String
just makes much much more sense than
() -> () -> String
which makes no sense at all imho
and i think it would be possible to infer the type in this case.
++ :: [a] -> [a] -> [a]
show :: Show e => e -> String
on :: (b -> b -> c) -> (d -> b) -> d -> d -> c
on (++) show :: d -> d -> c
(++) :: [a] -> [a] -> [a] = b -> b -> c
-> b = c = [a]
show :: Show e => e -> String = (d -> b)
-> b = String, Show d
-> c = String, a = Char
on (++) show :: Show d => d -> d -> String
is it really not possible to write an algorithm that can deduce this kind of stuff?
Am 08.06.2013 um 15:35 schrieb Brandon Allbery <allbery.b at gmail.com>:
> On Sat, Jun 8, 2013 at 9:02 AM, Peter Hall <peter.hall at memorphic.com> wrote:
> This is confusing me, and I'm wondering if it's a compiler bug. I have this:
>
> foo = (++) `on` show
>
> I'm expecting the type to be:
>
> foo :: Show a => a -> a -> String
>
> But GHCI is inferring:
>
> foo :: () -> () -> String
>
> No bug; it's the monomorphism restriction combining with extended defaulting to infer a monomorphic type. If you want to keep the monomorphism restriction and throw a type error, disable ExtendedDefaultRules.
>
> --
> brandon s allbery kf8nh sine nomine associates
> allbery.b at gmail.com ballbery at sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
More information about the Beginners
mailing list