Created
April 13, 2019 19:49
-
-
Save sheaf/a9607fb0ed3a013dc3215f6d0baf9dd7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GADTs #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE PolyKinds #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE TypeApplications #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| module Tuple where | |
| import Data.Kind | |
| ( Type ) | |
| data Nat :: Type where | |
| Zero :: Nat | |
| Succ :: Nat -> Nat | |
| data SNat :: Nat -> Type where | |
| SZero :: SNat Zero | |
| SSucc :: SingI n => SNat (Succ n) | |
| class SingI (n :: Nat) where | |
| sing :: SNat n | |
| instance SingI Zero where | |
| sing = SZero | |
| instance SingI n => SingI (Succ n) where | |
| sing = SSucc @n | |
| data Fin :: Nat -> Type where | |
| FZero :: Fin (Succ n) | |
| FSucc :: !(Fin n) -> Fin (Succ n) | |
| type Tuple (n :: Nat) (a :: Type) = Fin n -> a | |
| universe :: forall n. SingI n => [Fin n] | |
| universe = case sing @n of | |
| SZero -> [] | |
| ss@(SSucc :: SNat n) -> | |
| case ss of | |
| ( _ :: SNat (Succ m) ) -> | |
| FZero : map FSucc universe | |
| toList :: SingI n => Tuple n a -> [a] | |
| toList tup = map tup universe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment