Skip to content

Commit

Permalink
add instances
Browse files Browse the repository at this point in the history
  • Loading branch information
janmasrovira committed Aug 21, 2024
1 parent 835766e commit af72f25
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Stdlib/Data/List.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ applicativeListI : Applicative List :=
| [] _ := []
| (f :: fs) l := map f l ++ ap fs l
};

instance
monadListI : Monad List :=
mkMonad@{
bind := flip concatMap;
};
9 changes: 9 additions & 0 deletions Stdlib/Data/Maybe.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Stdlib.Trait.Ord open;
import Stdlib.Trait.Show open;
import Stdlib.Trait.Functor open;
import Stdlib.Trait.Applicative open;
import Stdlib.Trait.Monad open;

import Stdlib.Data.Bool.Base open;
import Stdlib.Data.String.Base open;
Expand Down Expand Up @@ -61,3 +62,11 @@ applicativeMaybeI : Applicative Maybe :=
| (just f) (just x) := just (f x)
| _ _ := nothing
};

instance
monadMaybeI : Monad Maybe :=
mkMonad@{
bind {A B} : Maybe A -> (A -> Maybe B) -> Maybe B
| nothing _ := nothing
| (just a) f := f a;
};
8 changes: 8 additions & 0 deletions Stdlib/Data/Result.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ applicativeResultI {err} : Applicative (Result err) :=
| (ok _) (error e) := error e
| (error e) _ := error e
};

instance
monadResultI {err} : Monad (Result err) :=
mkMonad@{
bind {A B} : Result err A -> (A -> Result err B) -> Result err B
| (error e) _ := error e
| (ok a) f := f a;
};
8 changes: 0 additions & 8 deletions Stdlib/Trait/Monad.juvix
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
module Stdlib.Trait.Monad;

import Stdlib.Data.Fixity open;
import Stdlib.Function open;
import Stdlib.Data.Bool.Base open;
import Stdlib.Data.Nat.Base open;
import Stdlib.Data.List.Base open;
import Stdlib.Data.Unit.Base open;
import Stdlib.Trait.Functor open;
import Stdlib.Trait.Applicative open;
import Stdlib.Trait.Foldable.Polymorphic open;
import Stdlib.Data.Unit.Base open;

trait
type Monad (m : Type -> Type) :=
Expand Down

0 comments on commit af72f25

Please sign in to comment.