- Our docs (docs.formality-lang.org)
- Our standard library (https://github.com/moonad/Formality-Base)
- Our Telegram channel (https://t.me/formality_lang)
One thing I've been particularly enjoying with Formality is how we can implement structures like `Monoid`, `Profunctor`, `Monad`, etc. directly as types, rather than requiring type class machinery.
Haskell can do this too, of course (as described in Gabriel Gonzalez's classic "Scrap your type classes" post http://www.haskellforall.com/2012/05/scrap-your-type-classes...), but what's really neat about Formality is that we can package propositions inside our "class types", so that only lawful instances can be created.
For example, here's our Semigroup type:
T Semigroup {A : Type}
| Semigroup
{ f : A -> A -> A
, associative : Associative(A,f)
}
Where `Associative` is an abstract property defined in `Algebra.Magma` (https://github.com/moonad/Formality-Base/blob/master/Algebra...) Associative : {A : Type, f : A -> A -> A} -> Type
{x : A, y : A, z : A} -> f(f(x,y),z) == f(x,f(y,z))
Then if you want to instantiate a particular `Semigroup` you have to do: and.Semigroup : Semigroup(Bool)
semigroup(~Bool, and, and.associative)
and.associative :
{ case a : Bool
, case b : Bool
, case c : Bool
} -> and(and(a,b),c) == and(a,and(b,c))
| true true true => refl(~true)
| true true false => refl(~false)
| true false true => refl(~false)
| true false false => refl(~false)
| false true true => refl(~false)
| false true false => refl(~false)
| false false true => refl(~false)
| false false false => refl(~false)
Providing proofs all over the place is a lot of work, but it's been a really fun experience that's taught me a lot about different algebraic or category theoretic structures. Julie Moronuki's post on [algebraic structures](https://argumatronic.com/posts/2019-06-21-algebra-cheatsheet...) has been an amazing resource.Particular files in base that exemplify this are:
- Category.fm (https://github.com/moonad/Formality-Base/blob/master/Categor...)
- Algebra.Lattice.fm (https://github.com/moonad/Formality-Base/blob/master/Algebra...)
- Control.Monad.fm (https://github.com/moonad/Formality-Base/blob/master/Control...)
- Data.Maybe.Control (https://github.com/moonad/Formality-Base/blob/master/Data.Ma...)
Still a ton of work to do, and a lot of these structures need instance proofs, so if anyone feels inspired, please don't hesitate to join our Telegram channel (https://t.me/formality_lang) or even DM me directly! (I'm @johnburnham on TG)
Comment adapted from a post on the Haskell subreddit: https://www.reddit.com/r/haskell/comments/d2gcyw/just_lettin...