-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add `Applicative` trait. - Add instances for `List`, `Maybe`, `Result`. --------- Co-authored-by: Paul Cadman <[email protected]>
- Loading branch information
1 parent
17a82dd
commit f51043d
Showing
10 changed files
with
101 additions
and
11 deletions.
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
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: [] |