Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created June 13, 2014 15:27
Show Gist options
  • Save qnikst/d11706f77c06a15eff9b to your computer and use it in GitHub Desktop.
Save qnikst/d11706f77c06a15eff9b to your computer and use it in GitHub Desktop.
type IsoKey = Int
-- | Serialized element
data ElementS = ElementS Int [IsoKey]
data Element = Element Int [Isotope] deriving (Show)
data Isotope = Isotope IsoKey Element deriving (Show) -- payload
to :: [ElementS] -> [Element]
to es = let result = map (\(ElementS z keys) -> Element z (map (\k -> Isotope k (un help k)) keys)) es
help = zip es result
in result
where
un :: [(ElementS, Element)] -> IsoKey -> Element
un elms k = snd $ head $ filter (\((ElementS z isos),_) -> elem k isos) elms
test = to [ElementS 1 [11,12,13], ElementS 2 [22,23,24]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment