Witchcraft & Quark

A presentation at VanFP in April 2016 in Vancouver, BC, Canada by Brooklyn Zelenka

Slide 1

Slide 1

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

Slide 2

Slide 2

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

Slide 3

Slide 3

Different results of FP principles Elixir Can feel (somewhat) imperative Lots of operational logic Thinks primarily in directional data “flow” (horizontal) Haskell Largely declarative Often think in abstractions (vertical)

Slide 4

Slide 4

Different results of FP principles Crossover Haskell has pipes Elixir has Enum I still want to try getting more “Haskell in Elixir” ¯_( )_/¯

Slide 5

Slide 5

Adding a Vertical Dimension to Elixir

Slide 6

Slide 6

WITCHCRAFT

Slide 7

Slide 7

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

Slide 8

Slide 8

Witchcraft Monoid, 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

Slide 9

Slide 9

Want partial application in Elixir Elixir 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…

Slide 10

Slide 10

MASSIVE DETOUR

Slide 11

Slide 11

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

Slide 12

Slide 12

Runtime Currying in Elixir

Slide 13

Slide 13

Runtime Currying in Elixir

Slide 14

Slide 14

Compile-Time Currying in Elixir

Slide 15

Slide 15

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

Slide 16

Slide 16

BACK TO

Slide 17

Slide 17

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

Slide 18

Slide 18

Just Protocols & Functions

Slide 19

Slide 19

Operators

Slide 20

Slide 20

Operators are Backwards?!

Slide 21

Slide 21

The Operators are Backwards?! Philosophical difference in Elixir Thinking horizontally (in “flow”) == data is the primary “subject”

Slide 22

Slide 22

Witchcraft so far <|> liftA2 liftM2 append <<< <~ <<~ apply bind Monad Applicative lift Functor join wrap Monoid identity

Slide 23

Slide 23

ADTs Want ADTs to get the most out of Witchcraft Elixir doesn’t have ADTs…

Slide 24

Slide 24

BUT ELIXIR HAS STRUCTS

Slide 25

Slide 25

Slide 26

Slide 26

Slide 27

Slide 27

Algae Internals are the topic of another talk

Slide 28

Slide 28

Q&A

Slide 29

Slide 29

Fin