This is due to the terrible restriction of monomorphism . Basically, GHCi likes to choose default types at runtime (the default Fractional type is Double ), but when you specify a type with :type , it selects the most common version. You can disable this behavior with the NoMonomorphismRestriction extension:
> :set -XNoMonomorphismRestriction > :set +t > 0.15 0.15 it :: Fractional a => a > :t 0.15 0.15 :: Fractional a => a
Although this extension has one of the more scary names, it is pretty simple when you break it:
Mono -> One Morph -> shape (type) ism -> thingy Monomorphism -> one shape thingy -> one type thingy -> thing with a single type
So basically this is a really long word that means "only type". Then with the βrestrictionβ you get that the restriction of monomorphism restricts things to one type. In this case, it restricts numbers (things) to type Double . Without this restriction, the type of numbers is limited only to the type class, which theoretically can be an infinite number of types.
source share