Created
January 9, 2014 13:41
-
-
Save mxswd/8334257 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 TypeFamilies, DataKinds, TypeOperators, FlexibleInstances, MultiParamTypeClasses, OverlappingInstances, ScopedTypeVariables, TemplateHaskell, FlexibleContexts, UndecidableInstances #-} | |
import Prelude hiding (head) | |
import GHC.TypeLits | |
import Acme.NumberSystem | |
numberSystem 10 | |
newtype Queue (k :: Nat) v = Queue [v] deriving (Show) | |
empty :: Queue 0 a | |
empty = Queue [] | |
add :: v -> Queue ks v -> Queue (Add ks 1) v | |
add v (Queue xs) = Queue (v:xs) | |
class Ke (k :: Nat) v where | |
head :: Queue k v -> (v, Queue (Sub k 1) v) | |
instance (1 <= k) => Ke k v where | |
head (Queue (x:xs)) = (x, Queue xs) | |
-- test | |
foo = add 10 $ add 2 $ add 1 empty | |
ok = snd . head . snd . head . snd . head $ foo | |
-- ohno = head snd . head . snd . head . snd . head $ foo -- type error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment