title |
---|
Curry like you are Haskell. |
git clone https://github.com/mhcurylo/fp-ts-workshop
cd fp-ts-workshop
yarn install
gh auth status -t
export GITHUB_TOKEN=copy your github token here
yarn start
Three computer languages named after Haskell Brooks Curry
In Haskell:
add x y = x + y
add2 = add 2
add2 3
const addUnCurry = (x, y) => x + y
// Curry
const addCurry = x => y => x + y;
const add2 = addCurry(2);
add2(3) == 5
Currying is a simple techninque, yet it allows one to achieve great things.
My goal is to show you how to use Currying in order to structure functional programms.
At the end of workshops I want you to know where to start if you want to write a fully fledged functional program in TypeScript.
-
Look at some curried functions.
-
Look at a scary functional codebase written using fp-ts.
-
Unpack some of it by doing exercises.
-
Run a scary functional codebase written using fp-ts.
-
Break
-
Look at a scary functional codebase written using fp-ts.
-
Process what we have seen by summoning ReaderTaskEither's minions.
-
Refactor a scary functional codebase written using fp-ts.
-
QUIZ.
type LazyArg<T> = () => T
type IO<T> = () => T
In Haskell everything is lazy so we do not need LazyArg and IO is actually another curried function, which would look like that:
type IO<T> = (rw: RealWorld) => [T, RealWorld]
type Reader<S, T> = (s: S) => T
type ReaderIO<S, T> = (s: S) => () => T
open ./src/App.ts
open ./src/exercises/1.unpack.spec.ts
yarn test
open ./src/index.ts
yarn start
Get a coffee, it will get worse.
map
flatMap
traverseArray
open ./src/exercises/2.ReaderWriterTask.spec.ts
yarn test
open ./src/gitworkflow.service.ts
Are all those functions curried? How do you call that way of curring?
Why go functional?
- It is a less subjective way to structure programms.
- It is a more correct way to structure programms.
What kind of monad is a function like that:
const of<S, T> = (v: T) => (s: S) => () => v;
How many possible implementations are there for this function:
type Fun<T> = (arg: T) => T
What was Bastien's favourite function?
Bastien is a workhorse of a developer.
What is Mateusz's fav function?
Mateusz enjoys when things stay the same.
How many instances are there of Johnatan's fav function?
Johnatan likes types. His favourite function is:
absurd: <T>(a: never) => T;