Skip to content

Instantly share code, notes, and snippets.

@dflima
Created November 12, 2012 19:17
Show Gist options
  • Save dflima/4061282 to your computer and use it in GitHub Desktop.
Save dflima/4061282 to your computer and use it in GitHub Desktop.
Transforming a MulSet data type to an array using Haskell
data MultSet = Nil | MS Int Int (MultSet)
deriving Show
ins k (Nil) = MS k 1 (Nil)
ins k (MS e n ms)
| k == e = MS e (n+1) ms
| otherwise = MS e n (ins k ms)
ltm [] = Nil
ltm (x:xs) = ins x (ltm xs)
sublist _ _ [] = []
sublist k i (x:xs)
| mod i k == 0 = x : ds
| otherwise = ds
where ds = sublist k (i+1) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment