diff options
author | Tom Smeding <tom@tomsmeding.com> | 2024-02-26 22:59:54 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2024-02-26 22:59:54 +0100 |
commit | 307919760c58e037ec3260fcd0c3c7f7227fd7aa (patch) | |
tree | 2d4451b230a243f4dec60d80b6e9557c2e486749 /src/Data/Bag.hs | |
parent | 49f4a26867eb81eb59cfea78374bb09dd45edfa3 (diff) |
WIP typecheck and other stuff
Diffstat (limited to 'src/Data/Bag.hs')
-rw-r--r-- | src/Data/Bag.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Data/Bag.hs b/src/Data/Bag.hs new file mode 100644 index 0000000..9cdce89 --- /dev/null +++ b/src/Data/Bag.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE DeriveTraversable #-} +module Data.Bag where + + +data Bag a + = BTwo (Bag a) (Bag a) + | BOne a + | BZero + deriving (Functor, Foldable, Traversable) + +instance Semigroup (Bag a) where (<>) = BTwo +instance Monoid (Bag a) where mempty = BZero + +instance Applicative Bag where + pure = BOne + + BZero <*> _ = BZero + _ <*> BZero = BZero + BOne f <*> b = f <$> b + BTwo b1 b2 <*> b = BTwo (b1 <*> b) (b2 <*> b) |