on master help sign in
Add Traversable instances for Maybe and (Vect n)
a449848Melvar Chen
lib/Prelude.idr+8
@@ -256,10 +256,18 @@ instance Monad (Vect n) where
256
256
257---- Traversable instances
257---- Traversable instances
258
258
259+instance Traversable Maybe where
260+ traverse f Nothing = pure Nothing
261+ traverse f (Just x) = [| Just (f x) |]
262+
259instance Traversable List where
263instance Traversable List where
260 traverse f [] = pure List.Nil
264 traverse f [] = pure List.Nil
261 traverse f (x::xs) = [| List.(::) (f x) (traverse f xs) |]
265 traverse f (x::xs) = [| List.(::) (f x) (traverse f xs) |]
262
266
267+instance Traversable (Vect n) where
268+ traverse f [] = pure Vect.Nil
269+ traverse f (x::xs) = [| Vect.(::) (f x) (traverse f xs) |]
270+
263---- some mathematical operations
271---- some mathematical operations
264
272
265%include C "math.h"
273%include C "math.h"