summaryrefslogtreecommitdiff
path: root/src/Data.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-12-06 21:23:21 +0100
committerTom Smeding <tom@tomsmeding.com>2024-12-06 21:23:21 +0100
commita2d7ddd2230b7f42fe46eb33ea6dee8eb7080fdc (patch)
tree990e51813d4d2438a3234f8a6dac67236b2d0c1e /src/Data.hs
parent263a3cef7543dfd447d5d75cc759fe95f7864105 (diff)
Start WIP compile-to-C
Diffstat (limited to 'src/Data.hs')
-rw-r--r--src/Data.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Data.hs b/src/Data.hs
index 1371902..fc39814 100644
--- a/src/Data.hs
+++ b/src/Data.hs
@@ -111,3 +111,16 @@ vecGenerate = \n f -> go n f SZ
unsafeCoerceRefl :: a :~: b
unsafeCoerceRefl = unsafeCoerce Refl
+
+data Bag t = BNone | BOne t | BTwo (Bag t) (Bag t) | BMany [Bag t]
+ deriving (Show, Functor, Foldable, Traversable)
+
+instance Applicative Bag where
+ pure = BOne
+ BNone <*> _ = BNone
+ BOne f <*> b = f <$> b
+ BTwo b1 b2 <*> b = BTwo (b1 <*> b) (b2 <*> b)
+ BMany bs <*> b = BMany (map (<*> b) bs)
+
+instance Semigroup (Bag t) where (<>) = BTwo
+instance Monoid (Bag t) where mempty = BNone