x :: Number
x = 0
const id<T> = (x: T) => x
type Id<T> = (x: T) => T
const id: Id = (x) => x
haskell에서는 소문자 a를 type으로 본다. ts에서 제네릭 T처럼..
id :: forall a. a -> a
함수를 일급객체로 다루면, 함수와 변수를 구분하지 않는다. 변수는 항상 같은 값을 리턴하는 함수로 볼 수도 있다.
always :: forall ab. a -> b -> a
always x y = x
apply :: forall ab. (a -> b) -> a -> b
second :: forall ab. a -> b -> b
// second를 만들지 않고 flip을 이용해서 구현
flip :: forall abc. (a -> b -> c) -> b -> a -> c
(a -> b -> a) -> (b -> a -> a)
// math
g(f(x))
// ts
compose(g, f)(x)
// haskell : g,f 타입의 함수와 x타입의 변수를 받자.
compose :: (a -> b) -> (? -> a) -> ? -> b
compose :: (b -> c) -> (a -> b) -> a -> c
compose gfx = g(fx)
// ts
pipe(f, g)(x)
// haskell
pipe :: (a -> b) -> (b -> c) -> (a -> c)
// pipe 함수를 flip에 compose를 주면? 완성.
pipe = flip compose
// Ramda에서의 map
map :: (a -> b) -> Array a -> Array b
map :: (a -> b) -> f a -> f b
// Array.prototype.map
// this를 ~로 표기하기도한다. 첫번째 인자
map :: Array a ~> (a -> b) -> Array b
// map 함수를 flip하면 아래와 같다.
then :: Promise a -> (a -> b) -> b
reduce :: (a -> b -> a) -> a -> Array b -> a