[Haskell-cafe] Restricted type classes

Neil Brown nccb2 at kent.ac.uk
Tue Sep 7 07:26:49 EDT 2010


On 07/09/10 05:24, wren ng thornton wrote:
>>> that other class would (most likely) be a subclass of pointed 
>>> functors. In
>>> any case, it does mean there's something of a mismatch between 
>>> singleton vs
>>> return/pure/point/unit.
>>
>> Not quite sure what you mean by a "mis-match"
> Of course, I'd expect singleton to obey the pointed law as well, so
>
> Just that they're not the same thing. For example, ZipList supports 
> pure but it has no meaningful instance of singleton since every 
> ZipList is infinite.
>
I don't believe that every ZipList is infinite (if this should be the 
case, the constructor shouldn't be exposed!), just that ZipLists created 
by "pure" are infinite -- that's the obvious definition to meet the 
Applicative laws.  You can quite happily use:

(+) <$> ZipList [1,2,3] <*> ZipList [4,5] == ZipList [5,7]

So ZipList does have a meaningful definition of singleton (singleton x = 
ZipList [x]; I'm sure there are other pointed functors that don't have a 
good definition for singleton), and a meaningful definition of pure, but 
they're not the same definition.

Thanks,

Neil.


More information about the Haskell-Cafe mailing list