IndiscriminateCoding / clarity

Licence: BSD-3-Clause License
Functional programming library for OCaml

Programming Languages

ocaml
1615 projects

Projects that are alternatives of or similar to clarity

monas
🦋 Scala monads for javascript
Stars: ✭ 21 (-64.41%)
Mutual labels:  monad
php-slang
The place where PHP meets Functional Programming
Stars: ✭ 107 (+81.36%)
Mutual labels:  monad
cefal
(Concepts-enabled) Functional Abstraction Layer for C++
Stars: ✭ 52 (-11.86%)
Mutual labels:  monad
apropos
Fast strong typed 'Either' data structure for typescript and flow
Stars: ✭ 20 (-66.1%)
Mutual labels:  monad
mercator
Automatic typeclass-based abstraction over monad-like types
Stars: ✭ 54 (-8.47%)
Mutual labels:  monad
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (-1.69%)
Mutual labels:  monad
maybe-baby
Minimize defensive coding. A JavaScript implementation of the Maybe monad.
Stars: ✭ 42 (-28.81%)
Mutual labels:  monad
free-arrow
Implementation of the Free Arrow in Scala and other helpful tools for working with Arrows
Stars: ✭ 14 (-76.27%)
Mutual labels:  monad
ts-belt
🔧 Fast, modern, and practical utility library for FP in TypeScript.
Stars: ✭ 439 (+644.07%)
Mutual labels:  monad
hkts
Functional programming tools: option, either, task, state, optics, etc.
Stars: ✭ 20 (-66.1%)
Mutual labels:  monad
result17
A rust like Result type for modern C++
Stars: ✭ 13 (-77.97%)
Mutual labels:  monad
f
a library to write async vert.x code similar as using java syntax
Stars: ✭ 22 (-62.71%)
Mutual labels:  monad
tagless-final-example
An example of how to create services using tagless final
Stars: ✭ 25 (-57.63%)
Mutual labels:  monad
ScrapeM
A monadic web scraping library
Stars: ✭ 17 (-71.19%)
Mutual labels:  monad
cpp stm free
Composable monadic STM for C++ on Free monads
Stars: ✭ 46 (-22.03%)
Mutual labels:  monad
alea
Coq library for reasoning on randomized algorithms [maintainers=@anton-trunov,@volodeyka]
Stars: ✭ 20 (-66.1%)
Mutual labels:  monad
harmony
C++ Monadologie
Stars: ✭ 26 (-55.93%)
Mutual labels:  monad
reflow
A light-weight lock-free series/parallel combined scheduling framework for tasks. The goal is to maximize parallelism in order to minimize the execution time overall.
Stars: ✭ 23 (-61.02%)
Mutual labels:  monad
Narvalo.NET
Applied functional patterns for C#. Money and Currency types. MVP framework. (Obsolete)
Stars: ✭ 16 (-72.88%)
Mutual labels:  monad
MtacAR
Mtac in Agda
Stars: ✭ 29 (-50.85%)
Mutual labels:  monad

Clarity - functional programming library for OCaml

Description

The goal of this project is to make pure functional programming idioms as useful as possible given OCaml's absence of higher-kinded types and typeclasses.

Main features are:

  • Standard "classes" like Functor-Applicative-Monad
  • Concrete instances like Reader-Writer-State
  • Useful data types like Either, These or Vector

Design notes

  • All concrete datatypes also have its constructors defined as values where name is prefixed with underscore. Sometimes it's more convenient to use "curried", first-class version of a constructor, e.g. following two are equivalent:
let long  = List.map (fun x -> Some x) a
let short = List.map _Some x
  • Applicative operator ap and its infix version (<~>) are "lazy" by its second argument. This allows for an applicative to "fail-fast" and don't compute unneeded values. "Strict" versions are called ap' and (<*>) respectively. "Laziness" here is just (unit -> 'a) closure, so you can use function combinators from Fn module for convenience:
open Clarity
open Option

(*
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<~>) : ('a -> 'b) t -> (unit -> 'a t) -> 'b t

val serialize : int -> int -> string -> string
val idx : int option
val long_computation : int -> int option
val title : string option
*)

open Fn

let res : string Option.t =
  map serialize idx
    <~> defer long_computation 1024
    <*> title
  • Right folds are also "lazy" by "accumulator" argument of a folding function. Strict right fold is called foldr'. This allows for shortcut when function no more needs data. For example, here is any function from Foldable module that checks if at least one element of a Foldable satisfies given predicate:
let any p = foldr (fun x a -> p x || a ()) (const false)

Documentation

You can find ocamldoc here.

Manual installation

$ make && make install
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].