https://github.com/saityi/felis
(⚠️ Work in Progress ⚠️) Category theoretic abstractions and implementations
https://github.com/saityi/felis
category-theory functional-programming standard-ml
Last synced: 3 months ago
JSON representation
(⚠️ Work in Progress ⚠️) Category theoretic abstractions and implementations
- Host: GitHub
- URL: https://github.com/saityi/felis
- Owner: Saityi
- License: mit
- Created: 2019-10-25T01:15:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-16T22:30:32.000Z (almost 4 years ago)
- Last Synced: 2025-06-12T20:06:19.797Z (4 months ago)
- Topics: category-theory, functional-programming, standard-ml
- Language: Standard ML
- Homepage:
- Size: 59.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Felis
A collection of common functional abstractions, including:
- Functor
- Applicatives
- Monads
- Foldable
And instances on them, defined where possible in Basis signature terms.
Include a small module of utility functions, tentatively named `Base`. Includes the types `id` and `either`, as well as utility functions like `id`, `const`, `uncurry`, `curry`, and `flip`, among others.
```sml
λ sml
Standard ML of New Jersey
- CM.make "felis.cm";
(* ListInstances is defined using the LIST signature from the standard library *)
(* Here, we instantiate it using SML/NJ's List structure *)
- structure L = ListInstances(List);
structure L :
sig
structure Monoid :
structure Monad :
structure Alternative :
structure Foldable :
functor Traversable :
end
- structure LT = L.Traversable(L.Monad);
structure LT : TRAVERSABLE
- structure LF = FunctorMethods(L.Monad);
structure LF :
sig
val <$> : ('a -> 'b) * 'a F.m -> 'b F.m
val $> : 'a F.m * 'b -> 'b F.m
val <$ : 'a * 'b F.m -> 'a F.m
val <&> : 'a F.m * ('a -> 'b) -> 'b F.m
val void : 'a F.m -> unit F.m
end
- open Base L LF;
- infix 6 <$>;
- (fn x => x + 1) <$> [1, 2, 3];
val it = [2,3,4] : int Monad.m
- void [1, 2, 3, 4, 5];
val it = [(),(),(),(),()] : unit Monad.m
- LT.traverse id [[0, 1], [1, 0]];
val it = [[0,1],[0,0],[1,1],[1,0]] : int Foldable.m Monad.m
```
NOTE: Due to the lack of ad-hoc polymorphism, I fear this isn't quite as useful as it could be, but I find after a little bit of boilerplate and `open`ing a couple modules, it's more useful than I expected. Pull requests welcome!