on master help sign in
Add Traversable instances for Maybe and (Vect n)
commita449848869cfac6130021518062c74ec537357cb authorMelvar Chen <Melvar.Chen@googlemail.com> dateSun 4 Aug 2013, 02:48 (13 years ago) parent545550f
1 file changed+8
lib/Prelude.idr+8
lib/Prelude.idr+8
@@ -256,10 +256,18 @@ instance Monad (Vect n) where
256256
257257---- Traversable instances
258258
259+instance Traversable Maybe where
260+ traverse f Nothing = pure Nothing
261+ traverse f (Just x) = [| Just (f x) |]
262+
259263instance Traversable List where
260264 traverse f [] = pure List.Nil
261265 traverse f (x::xs) = [| List.(::) (f x) (traverse f xs) |]
262266
267+instance Traversable (Vect n) where
268+ traverse f [] = pure Vect.Nil
269+ traverse f (x::xs) = [| Vect.(::) (f x) (traverse f xs) |]
270+
263271---- some mathematical operations
264272
265273%include C "math.h"