Skip to content

Instantly share code, notes, and snippets.

@NathanHowell
Created September 18, 2012 07:29
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 NathanHowell/a39ce17ca47798b0f0ef to your computer and use it in GitHub Desktop.
Save NathanHowell/a39ce17ca47798b0f0ef to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
import GHC.TypeLits
type family TakeN (n :: Nat) (m :: Nat) (b :: Bool) (xs :: [k]) :: [k]
type instance TakeN n m 'True xs = '[]
type instance TakeN n m 'False (x ': xs) = x ': TakeN (n+1) m (m <=? (n+1)) xs
type Take (n :: Nat) (xs :: [k]) = TakeN 0 n 'False xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment