[Haskell-cafe] Functors [Comments from OCaml Hacker Brian Hurt]
Luke Palmer
lrpalmer at gmail.com
Sat Jan 17 07:16:06 EST 2009
On Sat, Jan 17, 2009 at 5:04 AM, Andrew Coppin
<andrewcoppin at btinternet.com>wrote:
> Eugene Kirpichov wrote:
>
>> No, a functor is a more wide notion than that, it has nothing to do
>> with collections.
>> An explanation more close to truth would be "A structure is a functor
>> if it provides a way to convert a structure over X to a structure over
>> Y, given a function X -> Y, while preserving the underlying
>> 'structure'", where preserving structure means being compatible with
>> composition and identity.
>>
>>
>
> As far as I'm aware, constraints like "while preserving the underlying
> structure" are not expressible in Haskell.
Well, they're expressible *about* Haskell. I.e., for functors we require:
fmap id = id
fmap (f . g) = fmap f . fmap g
The first property is how we write "preserving underlying structure", but
this has a precise, well-defined meaning that we can say a given functor
obeys or it does not (and if it does not, we say that it's a bad instance).
But you are correct that Haskell does not allow us to require proofs of such
properties.
And indeed, some people break those properties in various ways, which some
consider okay if the breakage is not observable from outside a given
abstraction barrier. I'm on the fence about that...
Luke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090117/b07c6f56/attachment.htm
More information about the Haskell-Cafe
mailing list