-
-
Save NathanHowell/a39ce17ca47798b0f0ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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