Concepts is a partial port of Haskell's type class hierarchy to Dart. This library contains interfaces only with no implementations. This allows us to leverage Dart's type checker in conjunction with Dart's package manager to create executable, versioned and linkable specifications which double as layers of interoperation via polymorphism.
Like the algebraic structures in the haskell type class hierarchy, each given implementation must satisfy the interface as well as satisfy the laws associated to that interface.
SemiGroup represents data structures which can be merged associatively. Some people get an intuition from this by saying that it's two structures which can be summed.
a.merge(b).merge(c)
is equivalent to a.merge(b.merge(c))
A Monoid is a SemiGroup that also implements an identity value.
m.merge(m.empty())
is equivalent to m
m.empty().merge(m)
is equivalent to m
A functor is a structure which wraps a value and comes with a structure
preserving operations which allows you to transition the inner value to a new
state. This structure preserving operation is known as map
.
u.map((a) => a)
is equivalent to u
u.map((x) => f(g(x)))
is equivalent to u.map(g).map(f)
Applicative is a Functor lets you apply a function that is contained in a context itself to values that are also in the context.
const A((a) => a).ap(v)
is equivalent to v
const A(f).ap(const A(x))
is equivalent to const A(f(x))
u.ap(const A(y))
is equivalent to const A((f) => f(y)).ap(u)
A monad is an applicative functor that lets you transition a value to a new context within the same type hierarchy.
const M(a).expand(f)
is equivalent to f(a)
m.expand((n) => const M(n))
is equivalent to m
Add this to your package's pubspec.yaml file:
dependencies:
concepts: "^0.2.0"
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:concepts/concepts.dart';
Version  Uploaded  Documentation  Archive 

0.2.0  Aug 19, 2014  
0.1.0  Aug 19, 2014 
We analyzed this package on Jul 13, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Popularity:
Describes how popular the package is relative to other packages.
[more]

22  / 100 
Health:
Code health derived from static analysis.
[more]

91  / 100 
Maintenance:
Reflects how tidy and uptodate the package is.
[more]

0  / 100 
Overall score:
Weighted score of the above.
[more]

38 
Detected platforms: Flutter, web, other
No platform restriction found in primary library
package:concepts/concepts.dart
.
Maintain CHANGELOG.md
.
Changelog entries help clients to follow the progress in your code.
Homepage does not exists.
We were unable to access
https://github.com/JosephMoniz/dartconcepts
at the time of the analysis.
Package is too old.
The package was released more than two years ago.
Package is prev1 release.
While there is nothing inherently wrong with versions of
0.*.*
, it usually means that the author is still experimenting with the general direction API.
Fix analysis and formatting issues.
Analysis or formatting checks reported 6 hints.
Run
dartfmt
to formatlib/concepts.dart
.Run
dartfmt
to formatlib/src/applicative.dart
.Similar analysis of the following files failed:
lib/src/functor.dart
(hint)lib/src/monad.dart
(hint)lib/src/monoid.dart
(hint)lib/src/semigroup.dart
(hint)
Maintain an example.
Create a short demo in the
example/
directory to show how to use this package. Common file name patterns include:main.dart
,example.dart
or you could also useconcepts.dart
.