[Haskell-beginners] applicative default structure

David McBride toad3k at gmail.com
Thu Dec 22 15:46:45 UTC 2016


I get a Num ambiguous constraint error as well, but it is merely not giving
you the rest of the errors.

Prelude> let a1 = pure (1::Int)
Prelude> let a2 = pure (1::Int)
Prelude> a1 == a2
   • Ambiguous type variable ‘f0’ arising from a use of ‘a1’
      prevents the constraint ‘(Applicative f0)’ from being solved.

Furthermore you can't compare an IO a with an IO a, so it will still cause
an error.  But if you go:

Prelude>let a1 = 1
Prelude>let a2 = 1
Prelude>a1 == a2
True

Then it is totally fine with that.


On Thu, Dec 22, 2016 at 10:38 AM, Imants Cekusins <imantc at gmail.com> wrote:

> > what is the "default" structure if you don't specify any
>
> similar to:
>
> display::Show a => a -> String
> display = show
>
> fa::(Applicative f, Num a) => f a
> fa = pure 1
>
> f and a are *bounded* by Applicative and Num, so to say. No default. Or,
> it is typed however type is a bit broader than *
>
>
> > ​ In this case it defaults f to IO and a to Int,
>
> does it though?
>
>
> Prelude> let a1 = pure 1
> Prelude> let a2 = pure 1
> Prelude> a1 == a2
>
> <interactive>:20:1: error:
>     • Ambiguous type variable ‘a0’ arising from a use of ‘a1’
>       prevents the constraint ‘(Num a0)’ from being solved.
>
>
> _______________________________________________
> 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/20161222/8f5e196a/attachment.html>


More information about the Beginners mailing list