Idris-dev/examples/usefultypes.idr

21 lines
474 B
Idris
Raw Normal View History

intVec : Vect 5 Int
2012-01-07 03:20:03 +04:00
intVec = [1, 2, 3, 4, 5]
2012-01-07 03:20:03 +04:00
double : Int -> Int
double x = x * 2
vec : (n ** Vect n Int)
2012-01-07 03:20:03 +04:00
vec = (_ ** [3, 4])
2012-01-06 16:40:46 +04:00
2012-01-07 03:20:03 +04:00
list_lookup : Nat -> List a -> Maybe a
list_lookup _ Nil = Nothing
2013-07-26 23:05:47 +04:00
list_lookup Z (x :: xs) = Just x
2012-01-07 03:20:03 +04:00
list_lookup (S k) (x :: xs) = list_lookup k xs
2012-01-06 16:40:46 +04:00
2012-01-07 03:20:03 +04:00
lookup_default : Nat -> List a -> a -> a
lookup_default i xs def = case list_lookup i xs of
2012-01-06 16:40:46 +04:00
Nothing => def
Just x => x
2012-01-06 16:40:46 +04:00