Download - Witchcraft & Quark

Transcript
Page 1: Witchcraft & Quark

WITCHCRAFTEXPERIMENTS WRITING HIGHER-ORDER ABSTRACTIONS IN ELIXIR OR: PUTTING THE “FUN” BACK IN “FUNCTOR”

Page 2: Witchcraft & Quark

FP is a set of principles and practice, rather than one monolithic thing. We should embrace different ways of achieving these aims.

Page 3: Witchcraft & Quark

Different results of FP principlesElixir

Can feel (somewhat) imperative

Lots of operational logic

Thinks primarily in directional data “flow” (horizontal)

Haskell

Largely declarative

Often think in abstractions (vertical)

Page 4: Witchcraft & Quark

Different results of FP principlesCrossover

Haskell has pipes

Elixir has Enum

I still want to try getting more “Haskell in Elixir” ¯\_( )_/¯

Page 5: Witchcraft & Quark

Adding a Vertical Dimension to Elixir

Page 6: Witchcraft & Quark

WITCHCRAFT

Page 7: Witchcraft & Quark

Witchcraft

1.Witchcraft (also called witchery or spellcraft) broadly means the practice of, and belief in, magical skills and abilities that are able to be exercised individually, by designated social groups, or by persons with the necessary esoteric secret knowledge

2. A category-inspired library for Elixir

Page 8: Witchcraft & Quark

WitchcraftMonoid, Functor(s), Monad, Arrow, and Category for Elixir

Follows the Haskell Prelude and Control modules pretty closely

A lot of these rely on combinators and currying

Page 9: Witchcraft & Quark

Want partial application in ElixirElixir is an arity-based language

(Automatic) partial application isn’t a thing 😱

Currying isn’t a thing

foo(a) is a different function from foo(a, b)

Bootstrap time!

Massive detour…

Page 10: Witchcraft & Quark

MASSIVE DETOUR

Page 11: Witchcraft & Quark

Quark

Combinators for Elixir (id, flip, const, fix, SKI, &c)

How does Elixir now have these in the standard lib?!

Currying and (completely faked) partial application

Page 12: Witchcraft & Quark

Runtime Currying in Elixir

Page 13: Witchcraft & Quark

Runtime Currying in Elixir

Page 14: Witchcraft & Quark

Compile-Time Currying in Elixir

Page 15: Witchcraft & Quark

defpartial

Destroys the Elixir arity system 😅

Still really nice to use internally

Will get folded back in to defcurry eventually

Need to be able to specify only and except

Page 16: Witchcraft & Quark

BACK TO

Page 17: Witchcraft & Quark

Back to Witchcraft

Functors, monads, arrows, categories for Elixir

Follows the Haskell Prelude and Control modules pretty closely

A lot of these rely on combinators and currying

Page 18: Witchcraft & Quark

Just Protocols & Functions

Page 19: Witchcraft & Quark

Operators

Page 20: Witchcraft & Quark

Operators are Backwards?!

Page 21: Witchcraft & Quark

The Operators are Backwards?!

Philosophical difference in Elixir

Thinking horizontally (in “flow”) == data is the primary “subject”

Page 22: Witchcraft & Quark

Witchcraft so far

Functor

Monoid

Applicative

Monad

liftwrapapply

bind join

liftA2 liftM2 identityappend

<~ <<~

<<<

<|>

Page 23: Witchcraft & Quark

ADTs

Want ADTs to get the most out of Witchcraft

Elixir doesn’t have ADTs…

Page 24: Witchcraft & Quark

BUT ELIXIR HAS STRUCTS

Page 25: Witchcraft & Quark
Page 26: Witchcraft & Quark
Page 27: Witchcraft & Quark

Algae

Internals are the topic of another talk

Page 28: Witchcraft & Quark

Q&A

Page 29: Witchcraft & Quark

Fin


Top Related