All Projects → Risto-Stevcev → Bastet

Risto-Stevcev / Bastet

Licence: bsd-3-clause
A ReasonML/Ocaml library for category theory and abstract algebra

Programming Languages

ocaml
1615 projects
reason
219 projects
bucklescript
41 projects

Projects that are alternatives of or similar to Bastet

Category Theory
An axiom-free formalization of category theory in Coq for personal study and practical work
Stars: ✭ 562 (+181%)
Mutual labels:  monad, category-theory, category
Witchcraft
Monads and other dark magic for Elixir
Stars: ✭ 864 (+332%)
Mutual labels:  monad, algebra, category
Fp Resources
Functional programming great resources
Stars: ✭ 369 (+84.5%)
Mutual labels:  monad, algebra, category-theory
Rationale
Ramda inspired library of helper functions for ReasonML
Stars: ✭ 275 (+37.5%)
Mutual labels:  monad, reasonml
AlgebraicRelations.jl
Relational Algebra, now with more algebra!
Stars: ✭ 31 (-84.5%)
Mutual labels:  algebra, category-theory
free-arrow
Implementation of the Free Arrow in Scala and other helpful tools for working with Arrows
Stars: ✭ 14 (-93%)
Mutual labels:  monad, category-theory
mercator
Automatic typeclass-based abstraction over monad-like types
Stars: ✭ 54 (-73%)
Mutual labels:  monad, category-theory
Fluokitten
Category theory concepts in Clojure - Functors, Applicatives, Monads, Monoids and more.
Stars: ✭ 408 (+104%)
Mutual labels:  monad, category-theory
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (+169%)
Mutual labels:  monad, category-theory
Functional Examples
Examples with Functional JavaScript, following Professor Frisby's course
Stars: ✭ 179 (-10.5%)
Mutual labels:  monad, category-theory
Ltupatternfactory
Lambda the ultimate Pattern Factory: FP, Haskell, Typeclassopedia vs Software Design Patterns
Stars: ✭ 735 (+267.5%)
Mutual labels:  monad, category-theory
Fp Core.rs
A library for functional programming in Rust
Stars: ✭ 772 (+286%)
Mutual labels:  monad, category-theory
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (-84.5%)
Mutual labels:  monad, category-theory
Static Land
Specification for common algebraic structures in JavaScript based on Fantasy Land
Stars: ✭ 699 (+249.5%)
Mutual labels:  monad, algebra
Unplugged
Open book about math and computer science.
Stars: ✭ 1,189 (+494.5%)
Mutual labels:  algebra, category-theory
Functionaljava
Functional programming in Java
Stars: ✭ 1,472 (+636%)
Mutual labels:  monad, algebra
Symja android library
☕️ Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
Stars: ✭ 170 (-15%)
Mutual labels:  algebra
Funcadelic.js
Functional programming and category theory for everyday JavaScript development
Stars: ✭ 183 (-8.5%)
Mutual labels:  monad
Reduce.jl
Symbolic parser generator for Julia language expressions using REDUCE algebra term rewriter
Stars: ✭ 172 (-14%)
Mutual labels:  algebra
Add Reason
✨🐢 Dead simple tool for seamlessly integrating ReasonML into existing JavaScript projects.
Stars: ✭ 168 (-16%)
Mutual labels:  reasonml

Bastet

npm Build Status Coverage Status Release

A ReasonML/OCaml library for category theory and abstract algebra.

Documentation

See documentation

Installation

Bucklescript/ReasonML

Install the project:

yarn install bs-bastet --save

And add the dependency to your bs-dependencies in bsconfig.json:

"bs-dependencies": [
  "bs-bastet"
]

The project will be available under the Bastet namespace

Native

Install the project:

opam install bastet

Examples

# #require "bastet";;
# open Bastet;;
# module T = Functors.ListF.Option.Traversable;;
module T = Bastet.Functors.ListF.Option.Traversable

# T.sequence [Some "foo"; Some "bar"];;
- : string list option = Some ["foo"; "bar"]

# Functors.ListF.Int.Show.show [1; 1; 2; 3; 5; 8];;
- : string = "[1, 1, 2, 3, 5, 8]"

Suggested Usage

Use kliesli composition

The monadic equivalent of the |> operator is flat_map (>>=). Both are very useful for writing code that's easy to reason about as data all flows in one direction.

However, function composition (>.) and kliesli composition for monads (>=>) are often underused in code. Composing functions and monads monoidally like this in a concatenative style can make a codebase easier to read and can also prevent devs on the team from duplicating code.

Consider a typical use case. Often in a codebase you have something that fetches a value that may or may not exist ('a option). Splitting out this code into smaller functions and combining (and reusing) them with composition leads a lean code style:

# let ((>=>)) = Option.Infix.((>=>));;
val ( >=> ) : ('a -> 'b option) -> ('b -> 'c option) -> 'a -> 'c option =
  <fun>

# type form = { name: string; address: string option };;
type form = { name : string; address : string option; }

# let get_form () =
  (* Assume some side effect got the form here *)
  Some { name = "Foo"; address = Some "123 Bar St." };;
val get_form : unit -> form option = <fun>

# let get_address form = form.address;;
val get_address : form -> string option = <fun>

# let get_form_address = get_form >=> get_address;;
val get_form_address : unit -> string option = <fun>

# get_form_address ();;
- : string option = Some "123 Bar St."

Instantiated Functors

For interfaces based on functors, use already instantiated functors if available to avoid the extra boilerplate:

# Functors.ArrayF.Int.Additive.Fold_Map.fold_map
- : ('a -> int) -> 'a array -> int = <fun>

Don't Overuse Infix

Don't overuse infix operators. If the code is combinatorial it can make it more readable, but in a lot of cases the prefix operators are simpler and easier to read. If you do use infix operators, prefer local opens over global opens to avoid polluting the toplevel:

# let trim_all strings =
  let open List.Infix in
  StringLabels.trim <$> strings;;
val trim_all : string list -> string list = <fun>

# trim_all ["foo "; "bar"; "   baz"];;
- : string list = ["foo"; "bar"; "baz"]

Use Abbreviated Modules

Abbreviated modules can make code both terser and easier to read in some situations, like for example where two different semigroups are used in the same function and infix operators can't be used:

# type game = { score: int; disqualified: bool };;
type game = { score : int; disqualified : bool; }

# let total_score a b =
  let module I = Int.Additive.Semigroup in
  let module B = Bool.Disjunctive.Semigroup in
  { score = I.append a.score b.score; disqualified = B.append a.disqualified b.disqualified };;
val total_score : game -> game -> game = <fun>

# let result =
  let game_1 = { score = 4; disqualified = false }
  and game_2 = { score = 2; disqualified = true }
  in
  total_score game_1 game_2;;
val result : game = {score = 6; disqualified = true}

License

See LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].