Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{-# LANGUAGE DeriveFunctor #-}
module SetIsNotAFunctor where
import Data.Set (Set)
import qualified Data.Set as Set
-- | A type for annotating a value where equality and ordering only care
-- about the value.
data Ann ann a = Ann { annotation :: ann, value :: a }
deriving (Show, Functor)
instance Eq a => Eq (Ann ann a) where
Ann _ a == Ann _ b = a == b
instance Ord a => Ord (Ann ann a) where
compare (Ann _ a) (Ann _ b) = compare a b
anns :: Set (Ann String Int)
anns = Set.fromList [Ann "Hello" 1, Ann "Foobar" 0]
g :: Ann String Int -> Ann String Int
g = fmap (`div` 2)
f :: Ann String Int -> String
f = annotation
main = do
let lhs = Set.map (f . g) anns
print lhs
let rhs = (Set.map f . Set.map g) anns
print rhs
print (lhs == rhs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.