-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Applicative
trait
#115
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a615c22
add Applicative trait
janmasrovira 3fdbc4d
add Applicative instances
janmasrovira 8b00b55
rename >>
janmasrovira dc6ce2b
format
janmasrovira 95eda00
add mapM_
janmasrovira 0ca2d51
add liftA2, mapA_, replicateA
janmasrovira a1b3111
`make clean` runs `juvix clean` in test/
paulcadman f720fc8
Update stdlib for compat with applicative
paulcadman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ html: | |
PHONY: clean | ||
clean: | ||
rm -rf docs | ||
$(MAKE) -C test/ clean | ||
|
||
.PHONY: test | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import Stdlib.Data.Bool.Base open; | |
|
||
import Stdlib.Trait.Eq open; | ||
import Stdlib.Trait.Ord open; | ||
import Stdlib.Trait.Functor open; | ||
import Stdlib.Trait open; | ||
Comment on lines
7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you use |
||
|
||
{-# specialize: true, inline: case #-} | ||
instance | ||
|
@@ -39,3 +39,13 @@ functorResultI {err} : Functor (Result err) := | |
instance | ||
monomorphicFunctorResultI {err res} : Monomorphic.Functor (Result err res) res := | ||
fromPolymorphicFunctor; | ||
|
||
instance | ||
applicativeResultI {err} : Applicative (Result err) := | ||
mkApplicative@{ | ||
pure := ok; | ||
ap {A B} : Result err (A -> B) -> Result err A -> Result err B | ||
| (ok f) (ok x) := ok (f x) | ||
| (ok _) (error e) := error e | ||
| (error e) _ := error e | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- The unit type. | ||
module Stdlib.Data.Unit.Base; | ||
|
||
import Stdlib.Data.Bool.Base open; | ||
|
||
import Stdlib.Trait.Eq open; | ||
import Stdlib.Trait.Ord open; | ||
import Stdlib.Trait.Show open; | ||
import Stdlib.Trait.Foldable open; | ||
|
||
type Unit := | ||
--- The only constructor of ;Unit;. | ||
unit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Stdlib.Trait.Applicative; | ||
|
||
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.Foldable.Polymorphic open; | ||
import Stdlib.Data.Unit.Base open; | ||
|
||
trait | ||
type Applicative (f : Type -> Type) := | ||
mkApplicative { | ||
{{functor}} : Functor f; | ||
pure : {A : Type} -> A -> f A; | ||
ap : {A B : Type} -> f (A -> B) -> f A -> f B | ||
}; | ||
|
||
open Applicative public; | ||
|
||
--- Sequences computations. | ||
--- Note that this function will be renamed to >>> once IO becomses a polymorphic type and can be given an Applicative instance. | ||
applicativeSeq {f : Type -> Type} {{Applicative f}} {A B : Type} (fa : f A) (fb : f B) : f B := | ||
ap (map λ {_ b := b} fa) fb; | ||
|
||
--- lifts a binary function to ;Applicative; | ||
liftA2 {f : Type -> Type} {{Applicative f}} {A B C} (fun : A -> B -> C) : f A -> f B -> f C := | ||
map fun >> ap; | ||
|
||
syntax iterator mapA_ {init := 0; range := 1}; | ||
mapA_ | ||
{t : Type -> Type} | ||
{f : Type -> Type} | ||
{A B} | ||
{{Foldable t}} | ||
{{Applicative f}} | ||
(fun : A -> f B) | ||
(l : t A) | ||
: f Unit := rfor (acc := pure unit) (x in l) {applicativeSeq (fun x) acc}; | ||
|
||
replicateA {f : Type -> Type} {A} {{Applicative f}} : Nat -> f A -> f (List A) | ||
| zero _ := pure [] | ||
| (suc n) x := liftA2 (::) x (replicateA n x); | ||
|
||
when {f : Type -> Type} {{Applicative f}} : Bool -> f Unit -> f Unit | ||
| false _ := pure unit | ||
| true a := a; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# This file was autogenerated by Juvix version 0.6.4. | ||
# This file was autogenerated by Juvix version 0.6.5. | ||
# Do not edit this file manually. | ||
|
||
version: 2 | ||
checksum: fe279cadfedcac3f17d3557f5b1bbc168a153b29b6876bd56df33e21aad59ee5 | ||
checksum: 74c7b4f7ff78859f15da9fa14ede6df5397c698d1efdcd5cc0f435d5cbb59e9d | ||
dependencies: | ||
- path: ../ | ||
dependencies: [] | ||
- git: | ||
name: anoma_juvix-quickcheck | ||
ref: eca0d109869eeb7b708162634f4917f270139da1 | ||
ref: 104c749950480ed5dad42c7385a020ff31ca8875 | ||
url: https://github.com/anoma/juvix-quickcheck | ||
dependencies: | ||
- git: | ||
name: anoma_juvix-stdlib | ||
ref: 297601a98dcace657aaff6e42945f1430647885b | ||
ref: 0ca2d5181e7c98eceace5c12bfd0a8cfb3d4d132 | ||
url: https://github.com/anoma/juvix-stdlib | ||
dependencies: [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use
import Stdlib.Trait open
are the otherTrait
imports redundant?