[Haskell] ANNOUNCE: set-monad
Derek Elkins
derek.a.elkins at gmail.com
Sat Jun 16 21:53:08 CEST 2012
On Sat, Jun 16, 2012 at 3:47 AM, Dan Burton <danburton.email at gmail.com> wrote:
>
> Convenience aside, doesn't the functor instance conceptually violate some sort of law?
>
> fmap (const 1) someSet
>
> The entire shape of the set changes.
>
> fmap (g . h) = fmap g . fmap h
>
> This law wouldn't hold given the following contrived ord instance
>
> data Foo = Foo { a, b :: Int }
> instance Ord Foo where
> compare = compare `on` a
>
> Given functions
>
> h foo = foo { a = 1 }
> g foo = foo { a = b foo }
>
> Does this library address this? If so, how? If not, then you'd best note it in the docs.
Your hypothesis is false. You should at least try out your example.
It's easy to show that (fmap g . fmap h) x is true for all x (at least
ignoring potential issues with strictness.) The thing to note is that
fmap h x is not a set, it is an expression tree (which is only
observable via run.) The law that ends up failing is toList .
fromList /= id, i.e. fmap g . toList . fromList . fmap h /= fmap g .
fmap h
More information about the Haskell
mailing list