Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Created February 26, 2012 06:10
Show Gist options
  • Save dtchepak/1914169 to your computer and use it in GitHub Desktop.
Save dtchepak/1914169 to your computer and use it in GitHub Desktop.
Playing around with take and fold
data TakeState a = TakeState Int a deriving (Show)
take' n =
let f (TakeState i acc) head = if i==n then (TakeState i acc) else (TakeState (i+1) (acc++[head]))
in foldl f (TakeState 0 [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment