Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@steshaw
Created May 6, 2020 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steshaw/868c3c474f2094f2f79c272f2e2bbb09 to your computer and use it in GitHub Desktop.
Save steshaw/868c3c474f2094f2f79c272f2e2bbb09 to your computer and use it in GitHub Desktop.
data Decl a
= TypeSig String a
| Law String a a
| FunModel String a
| TypeModel String a
| Import a
| Other a
deriving (Show)
decls =
[ TypeSig "Hello" 1,
Law "Fred" 1 42,
FunModel "Fun" 2,
Import 10,
Other 99,
Law "Be good" 2 3,
TypeModel "huh" 0
]
partitionThem :: [Decl a] -> ([Decl a], [Decl a], [Decl a], [Decl a])
partitionThem = foldMap pickSlot
where
pickSlot lw@Law {} = ([lw], mempty, mempty, mempty)
pickSlot fm@FunModel {} = (mempty, [fm], mempty, mempty)
pickSlot tm@TypeModel {} = (mempty, mempty, [tm], mempty)
pickSlot other = (mempty, mempty, mempty, [other])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment