Skip to content

Instantly share code, notes, and snippets.

@Ikke
Created December 21, 2014 16:55
Show Gist options
  • Save Ikke/c413ffe389b021253965 to your computer and use it in GitHub Desktop.
Save Ikke/c413ffe389b021253965 to your computer and use it in GitHub Desktop.
module Golf where
skips :: [a] -> [[a]]
skips xs = map (\i -> takeEvery (fst i) (snd i)) $ createZipList xs
where
createZipList xs = zip [1..] $ take (length xs) $ repeat xs
takeEvery :: Int -> [a] -> [a]
takeEvery n xs =
case drop (n-1) xs of
(y:ys) -> y : takeEvery n ys
[] -> []
main = do
print (skips [])
Golf.hs:16:5:
No instance for (Show a0) arising from a use of ‘print’
The type variable ‘a0’ is ambiguous
Note: there are several potential instances:
instance Show Double -- Defined in ‘GHC.Float’
instance Show Float -- Defined in ‘GHC.Float’
instance (Integral a, Show a) => Show (GHC.Real.Ratio a)
-- Defined in ‘GHC.Real’
...plus 24 others
In a stmt of a 'do' block: print (skips [])
In the expression: do { print (skips []) }
In an equation for ‘main’: main = do { print (skips []) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment