[Haskell-beginners] Type signatures returned with :t

Andreas Perstinger andipersti at gmail.com
Sun Sep 19 04:46:35 UTC 2021


On 19.09.21 00:30, Galaxy Being wrote:
>> :t Just True
> Just True :: Maybe Bool

What's the type of `Just`?

 > :t Just
Just :: a -> Maybe a

So `Just` is a constructor function that takes a value of type `a` and 
gives you back a value of type `Maybe a`.

In your example you provide a concrete type for `a` (`True :: Bool`) so 
the type of the result is `Maybe Bool`.

>> :t Left True
> Left True :: Either Bool b

As above what's the type of `Left`?

 > :t Left
Left :: a -> Either a b

Again, `Left` is a constructor function that takes a single value of type 
`a` but now returns a value of type `Either a b`, i.e. it has two type 
variables.

If you specify the type of `a` (again `Bool` in your example), `b` is 
still unspecified/polymorphic and that's why the resulting type is `Either 
Bool b`.

Bye, Andreas


More information about the Beginners mailing list