[Haskell-beginners] Why is there no notion of a one-tuple (e.g., a '([])' as opposed to a '[]') in Haskell?

Ben Lippmeier Ben.Lippmeier at anu.edu.au
Thu Sep 25 00:23:51 EDT 2008


On 25/09/2008, at 11:27 AM, ajb at spamcop.net wrote:
>>> Haskell doesn't have a notion of a one-element tuple.
>>
>> Why not?
>
> Perhaps more crucially, it's hard to see where such a thing would
> be useful.

IORef, and ML's ref types are sort of one element tuples. The ML ref  
type is more so, because you don't need a special monad to read and  
write its contents..

Ref types are useful because many different parts of your program can  
hold pointers to the outer constructor. By updating the constructor to  
hold a different value, you propagate this new value throughout your  
program in a single, constant time operation.

Ref types can be very useful in practice. IORefs are used GHC's type  
inferencer to implement type substitution. They're also heavily used  
in interactive programs like frag[1] to propagate the current user  
input state throughout the program.

Ben.

[1] http://www.haskell.org/haskellwiki/Frag




More information about the Beginners mailing list