[Haskell-beginners] Why isn't :t (1+1) Integer

Alex Belanger i.caught.air at gmail.com
Fri Sep 30 03:47:17 UTC 2016


Those are not demonstrations of the defaulting rules in action though.

As far as I know, :t is agnostic to those and will keep showing the
original polymorphic version, since you're not in a context where GHC has
to sacrifice the polymorphic type and commit to a monomorphic one using a
default, like when expressions are evaluated.

Also I think that's effective just for the REPL (it uses extended
defaulting rules that are more lax) and is done for convenience. If it was
during a GHC build, you'd get loud warning when something is defaulted.

Try `reverse []` for fun vs. `:t reverse []`.

On Sep 29, 2016 7:48 PM, "Lai Boon Hui" <laiboonh at gmail.com> wrote:

> Hi,
> i read that the default type for Num is Integer.
> If we specify a type for one of the arguments:
> :t (1 + 1::Double) is Double
>
> If we don't, i expect the default type for Num to come into play:
> However :t (1 + 1) is Num a => a
>
> Why is that so?
>
> --
> Best Regards,
> Boon Hui
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160929/bd50ac7f/attachment.html>


More information about the Beginners mailing list