Lamblichus.Functor (lamblichus v0.1.0)
Lamblichus is a elixir macro for implemented functor, like in haskell
Functors: uniform action over a parameterized type, generalizing the map function on lists.
## Usage
You can define an Lamblichus Functor by calling use Lamblichus.Functor with a few
options in your module.
defmodule Stage.Init do
# If you don't want to import a function or macro from `Kernel`,
# use the `:except` option and then list the function/macro by arity:
import Kernel, except: [<~>: 2, <|>: 2]
use Lamblichus.Functor
endYou can now call the functor macro:
(fn n -> n * 2 end) <~> [1, 2, 3]## Concerns Well, elixir it's nice a language, we can using infix ops too But, we can't define our own operators like in haskell
We would either have to modify the Elixir parser directly (and recompile Elixir) -> For more details @see https://github.com/elixir-lang/elixir/blob/1907914cf0d9d25b32373d3c8ad6b4b59877baaf/lib/elixir/src/elixir_parser.yrl#L73
Happy hacking!
Link to this section Summary
Functions
functor_flipped as <|>
functor as <~>
A Functor is a type constructor which supports a mapping operation map
Flipped version of functor.
Link to this section Types
(a -> b) -> f a -> f b
@type t() :: any()
assume this type as your expected -,-
Link to this section Functions
fa <|> f
functor_flipped as <|>
f <~> fa
functor as <~>
A Functor is a type constructor which supports a mapping operation map
map can be used to turn functions a -> b into functions
f a -> f b whose argument and return types use the type constructor f
to represent some computational context.
The law of identity
∀x. (id <$> x) ≅ xThe law of composition
∀f g x.(f . g <$> x) ≅ (f <$> (g <$> x))
Flipped version of functor.