Skip to content

Instantly share code, notes, and snippets.

@ukitaka
Last active July 2, 2016 09:46
Show Gist options
  • Save ukitaka/e64768007244816dfd27e78964560f0d to your computer and use it in GitHub Desktop.
Save ukitaka/e64768007244816dfd27e78964560f0d to your computer and use it in GitHub Desktop.
Haskell.swift
func const<A, B>(a: A) -> B -> A {
return { _ in a }
}
func curry<A, B>(_ function: (A) -> B) -> (A) -> B {
return { (`a`: A) -> B in function(`a`) }
}
func curry<A, B, C>(_ function: (A, B) -> C) -> (A) -> (B) -> C {
return { (`a`: A) -> (B) -> C in { (`b`: B) -> C in function(`a`, `b`) } }
}
func curry<A, B, C, D>(_ function: (A, B, C) -> D) -> (A) -> (B) -> (C) -> D {
return { (`a`: A) -> (B) -> (C) -> D in { (`b`: B) -> (C) -> D in { (`c`: C) -> D in function(`a`, `b`, `c`) } } }
}
func id<A>(a: A) -> A {
return a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment