Using defn for definitions (type classes)
This commit is contained in:
parent
6a08ad31f0
commit
4962291f89
1 changed files with 17 additions and 17 deletions
|
@ -3,12 +3,12 @@
|
|||
```
|
||||
given A
|
||||
class Semigroup
|
||||
fn combine: A -> A -> A
|
||||
defn combine: A -> A -> A
|
||||
end class
|
||||
|
||||
given A :: Semigroup
|
||||
class Monoid
|
||||
fn empty: A
|
||||
defn empty: A
|
||||
end class
|
||||
|
||||
--- Type class for type constructors which can be mapped over.
|
||||
|
@ -27,22 +27,22 @@ class Functor
|
|||
--- @param fa The functor input.
|
||||
--- @param f The function to transform data from `A` to `B`.
|
||||
given A, B
|
||||
fn map: F A -> (A -> B) -> F B
|
||||
defn map: F A -> (A -> B) -> F B
|
||||
end class
|
||||
|
||||
given F * :: Functor
|
||||
class Apply
|
||||
given A, B
|
||||
fn ap: F (A -> B) -> F A -> F B
|
||||
defn ap: F (A -> B) -> F A -> F B
|
||||
end class
|
||||
|
||||
given F * :: Apply
|
||||
class Applicative
|
||||
given A
|
||||
fn pure: A -> F A
|
||||
defn pure: A -> F A
|
||||
|
||||
fn unit: F ()
|
||||
pure ()
|
||||
fn unit: F
|
||||
λ => pure ()
|
||||
end fn
|
||||
end class
|
||||
|
||||
|
@ -51,18 +51,18 @@ given F * :: Applicative
|
|||
instance Functor F
|
||||
given A, B
|
||||
fn map: F A -> (A -> B) -> F B
|
||||
fa f => ap (pure f) fa
|
||||
λ fa f => ap (pure f) fa
|
||||
end fn
|
||||
end instance
|
||||
|
||||
given F * :: Apply
|
||||
class FlatMap
|
||||
given A, B
|
||||
fn fmap: F A -> (A -> F B) -> F B
|
||||
defn fmap: F A -> (A -> F B) -> F B
|
||||
|
||||
given A
|
||||
fn flatten: F (F A) -> F A
|
||||
ffa => fmap ffa (fa => fa)
|
||||
λ ffa => fmap ffa (fa => fa)
|
||||
end fn
|
||||
end class
|
||||
|
||||
|
@ -80,13 +80,13 @@ end instance
|
|||
given F * *
|
||||
class Bifunctor
|
||||
given A, B, C, D
|
||||
fn bimap F A B -> (A -> C) -> (B -> D) -> F C D
|
||||
defn bimap F A B -> (A -> C) -> (B -> D) -> F C D
|
||||
end class
|
||||
|
||||
given F * :: Functor
|
||||
class CoFlatMap
|
||||
given A, B
|
||||
fn cofmap: F A -> (F A -> B) -> F B
|
||||
defn cofmap: F A -> (F A -> B) -> F B
|
||||
|
||||
given A
|
||||
fn coflatten: F A -> F (F A)
|
||||
|
@ -97,17 +97,17 @@ end class
|
|||
given F * :: CoFlatMap
|
||||
class CoMonad
|
||||
given A
|
||||
fn extract: F A -> A
|
||||
defn extract: F A -> A
|
||||
end class
|
||||
|
||||
given A
|
||||
class Show
|
||||
fn show: A -> String
|
||||
defn show: A -> String
|
||||
end class
|
||||
|
||||
given A, B
|
||||
class Eq
|
||||
fn eq: A -> B -> Boolean
|
||||
defn eq: A -> B -> Boolean
|
||||
|
||||
fn neq: A -> B -> Boolean
|
||||
λ x y => not (eq x y)
|
||||
|
@ -130,7 +130,7 @@ end enum
|
|||
|
||||
given A
|
||||
class Compare
|
||||
fn compare: A -> A -> Comparison
|
||||
defn compare: A -> A -> Comparison
|
||||
end class
|
||||
|
||||
given A :: Compare
|
||||
|
@ -146,6 +146,6 @@ end instance
|
|||
|
||||
given A
|
||||
class HashCode
|
||||
fn hash_code: A -> Int32
|
||||
defn hash_code: A -> Int32
|
||||
end class
|
||||
```
|
||||
|
|
Loading…
Add table
Reference in a new issue