-
-
Save glaebhoerl/f606757a91c66bccc0ea 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
-- Code taken from http://stackoverflow.com/questions/12735274/breaking-data-set-integrity-without-generalizednewtypederiving/12744568#12744568 | |
-- Discussion on haskell-cafe: http://thread.gmane.org/gmane.comp.lang.haskell.cafe/100870 | |
-- http://www.haskell.org/pipermail/haskell-cafe/2012-October/103984.html | |
-- Modified to remove orphan instances by rwbarton | |
-- Simplified by glaebhoerl | |
module A (A(..), Set, empty, insert, on) where | |
import Data.Set | |
import Data.Function | |
data A x y = B | C deriving (Eq, Show) |
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 FlexibleInstances #-} | |
module B where | |
import A | |
data B = MkB | |
instance Ord (A B c) where | |
compare = compare `on` (== B) | |
insertB :: A B c -> Set (A B c) -> Set (A B c) | |
insertB = insert |
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 FlexibleInstances #-} | |
module C where | |
import A | |
data C = MkC | |
instance Ord (A b C) where | |
compare = compare `on` (== C) | |
insertC :: A b C -> Set (A b C) -> Set (A b C) | |
insertC = insert |
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
module Main where | |
import A | |
import B | |
import C | |
test :: Set (A B C) | |
test = insertC B $ insertB B $ insertB C $ empty | |
main :: IO () | |
main = print test | |
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
!glaebhoerl@e135:~/test/f606757a91c66bccc0ea$ ghc -Wall -XSafe -fforce-recomp --make D.hs | |
[1 of 4] Compiling A ( A.hs, A.o ) | |
[2 of 4] Compiling B ( B.hs, B.o ) | |
[3 of 4] Compiling C ( C.hs, C.o ) | |
[4 of 4] Compiling Main ( D.hs, D.o ) | |
Linking D ... | |
!glaebhoerl@e135:~/test/f606757a91c66bccc0ea$ ./D | |
fromList [B,C,B] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment