[Haskell-beginners] type variables

Thomas haskell at phirho.com
Tue Aug 24 16:25:36 EDT 2010


Thank you Brent, Daniel & Jürgen!

Got it. Actually it seems obvious now.
I guess my misleading expectations of what type variables are made me 
sort of blind...

Again: Thanks,
Thomas


On 24.08.2010 14:47, Brent Yorgey wrote:
> On Tue, Aug 24, 2010 at 01:09:56PM +0200, Thomas wrote:
>>
>> But if I change the type declaration of 'testFold' to:
>> testFold :: XMLCallback a
>> it will not compile.
>>
>> I thought that 'a' is a type /variable/ thus able to hold any type,
>> for example, but not limited to '[(XMLTreeNode, [Int],
>> [XMLTreeNode])]'. Why do I need to be that much more specific in the
>> declaration for 'testFold'?
>
> Daniel has already given a more detailed answer, but just to emphasize
> the main point a bit more:
>
>    testFold :: XMLCallback a
>
> means that testFold *should work no matter what a is*.  But as Daniel
> has explained, this is not the case; testFold only works for certain
> specific types in place of a.  Type variables are not a shortcut used
> when one can't be bothered to give the type in more detail; rather,
> they are strong assertions that *any type will work*.
>
> -Brent
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list