Skip to content
Snippets Groups Projects
Commit ff71f075 authored by Tobias Haslop's avatar Tobias Haslop
Browse files

Add Folddable/Traversable instances in furthark

parent 7b399ca4
No related branches found
No related tags found
1 merge request!296Draft: Add quantified superclasses to Bifoldable and Bitraversable
Pipeline #78837 passed
......@@ -11,3 +11,71 @@ index cbdc3e1..9e13b5e 100644
import Data.Int (Int64)
import Data.List (foldl', transpose)
import Data.Map qualified as M
diff --git a/src/Futhark/IR/Syntax/Core.hs b/src/Futhark/IR/Syntax/Core.hs
index f61a679..f2023f4 100644
--- a/src/Futhark/IR/Syntax/Core.hs
+++ b/src/Futhark/IR/Syntax/Core.hs
@@ -248,7 +248,13 @@ instance Bitraversable TypeBase where
bitraverse _ _ (Mem s) = pure $ Mem s
instance Functor (TypeBase shape) where
- fmap = second
+ fmap = fmapDefault
+
+instance Foldable (TypeBase shape) where
+ foldMap = foldMapDefault
+
+instance Traversable (TypeBase shape) where
+ traverse = bitraverse pure
instance Bifunctor TypeBase where
bimap = bimapDefault
diff --git a/src/Language/Futhark/Syntax.hs b/src/Language/Futhark/Syntax.hs
index 527c5ad..06615b9 100644
--- a/src/Language/Futhark/Syntax.hs
+++ b/src/Language/Futhark/Syntax.hs
@@ -287,7 +287,13 @@ instance Bitraversable RetTypeBase where
bitraverse f g (RetType dims t) = RetType dims <$> bitraverse f g t
instance Functor (RetTypeBase dim) where
- fmap = second
+ fmap = fmapDefault
+
+instance Foldable (RetTypeBase dim) where
+ foldMap = foldMapDefault
+
+instance Traversable (RetTypeBase dim) where
+ traverse = bitraverse pure
instance Bifunctor RetTypeBase where
bimap = bimapDefault
@@ -318,7 +324,13 @@ instance Bitraversable ScalarTypeBase where
bitraverse f g (Sum cs) = Sum <$> (traverse . traverse) (bitraverse f g) cs
instance Functor (ScalarTypeBase dim) where
- fmap = second
+ fmap = fmapDefault
+
+instance Foldable (ScalarTypeBase dim) where
+ foldMap = foldMapDefault
+
+instance Traversable (ScalarTypeBase dim) where
+ traverse = bitraverse pure
instance Bifunctor ScalarTypeBase where
bimap = bimapDefault
@@ -342,7 +354,13 @@ instance Bitraversable TypeBase where
Array <$> g a <*> pure u <*> traverse f shape <*> bitraverse f pure t
instance Functor (TypeBase dim) where
- fmap = second
+ fmap = fmapDefault
+
+instance Foldable (TypeBase dim) where
+ foldMap = foldMapDefault
+
+instance Traversable (TypeBase dim) where
+ traverse = bitraverse pure
instance Bifunctor TypeBase where
bimap = bimapDefault
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment