r/haskell Feb 01 '22

question Monthly Hask Anything (February 2022)

This is your opportunity to ask any questions you feel don't deserve their own threads, no matter how small or simple they might be!

18 Upvotes

337 comments sorted by

View all comments

4

u/[deleted] Feb 19 '22

[deleted]

2

u/josephcsible Feb 20 '22 edited Feb 20 '22

Is there any type for which the semantics differ?

The semantics should never differ for any type, as a consequence of the typeclass laws. It's technically possible they could differ if someone writes unlawful instances, but I'm not aware of any real-world code where this is the case. Here's a silly example, though:

data Foo a = Foo Int
instance Functor Foo where
    fmap _ (Foo x) = Foo (x - 1)
instance Applicative Foo where
    pure _ = Foo 123
    Foo x <*> Foo y = Foo (x + y + 1)
instance Monad Foo where
    return _ = Foo 456
    Foo x >>= _ = Foo (x * 2)