Created
March 25, 2019 00:04
-
-
Save parsonsmatt/621cafbc47ba204e606134e8dcdeff08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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