Created
January 30, 2020 21:58
-
-
Save monadplus/f3197502a4ca4dcbc99e2d4ac9044558 to your computer and use it in GitHub Desktop.
TODO improve this solution
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
data Vector (n :: Nat) (a :: Type) where | |
VNil :: Vector 'Z a | |
VCons :: a -> Vector n a -> Vector ('S n) a | |
data SmallerThan (limit :: Nat) where | |
SmallerThanZ :: SmallerThan ('S 'Z) | |
SmallerThanN :: SmallerThan n -> SmallerThan ('S n) | |
(!!!) :: Vector n a -> SmallerThan n -> a | |
(!!!) (VCons a _) SmallerThanZ = a | |
(!!!) (VCons _ v) (SmallerThanN n) = v !!! n | |
-- let vector = VCons 1 (VCons 2 VNil) | |
-- >>> vector !!! (SmallerThanN SmallerThanZ) | |
-- 2 | |
-- >>> vector !!! (SmallerThanN (SmallerThanN SmallerThanZ)) | |
-- • Couldn't match type ‘'S 'Z’ with ‘'Z’ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment