Created
May 18, 2017 02:25
-
-
Save rampion/e05fad464a0c5cd4916fc0c027bc8467 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 KindSignatures #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE PatternSynonyms #-} | |
{-# LANGUAGE ViewPatterns #-} | |
module Fin where | |
data Nat = Z | S Nat | |
newtype Fin (n :: Nat) = Fin { unFin :: Int } | |
pattern FZ :: Fin ('S n) | |
pattern FZ = Fin 0 | |
pattern FS :: Fin n -> Fin ('S n) | |
pattern FS f <- (finPred -> Just f) | |
where FS = finSucc | |
finPred :: Fin ('S n) -> Maybe (Fin n) | |
finPred (Fin 0) = Nothing | |
finPred (Fin i) = Just (Fin (pred i)) | |
finSucc :: Fin n -> Fin ('S n) | |
finSucc (Fin i) = Fin (succ i) | |
x :: Int | |
x = case FZ of { FS (Fin i) -> i ; _ -> 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment