[Haskell-cafe] Word rigid in "`a' is a rigid type variable..."

James ‘Twey’ Kay twey at twey.co.uk
Thu Nov 14 14:39:22 UTC 2013


On 2013-11-14 10:33, Vlatko Basic wrote:

>  Can you recommend any resources that helped you in better
> understanding?

I generally find it easier to think in terms of type functions: a type 
function is a function that takes a type and returns a type, written 
perhaps Λa → E (where a is a type, and bound in E).

The type of a Haskell function with a type variable a is a type function 
whose parameter just happens to be automatically filled in by the type 
checker at the call site:

   id ∷ Λa → a → a
   id _ x = x

That makes it quite clear (to me, at least) where the type gets passed 
in.  It's also pretty similar to a Java generic, which just has slightly 
different syntax for the type parameter:

   <A> A id(A x) { return x; }

In Java, you'd call that function (if I remember my Java syntax 
correctly) like

   <Integer>id(3);

the Haskell-with-type-functions version looks the same, except perhaps 
without the pointy brackets:

   id Integer 0

where

   id Integer            ∷ Integer          → Integer
   id Char               ∷ Char             → Char
   id (Either Char Bool) ∷ Either Char Bool → Either Char Bool

et cetera.

   HTH,
     — Twey


More information about the Haskell-Cafe mailing list