Logo

Programming-Idioms

History of Idiom 37 > diff from v28 to v29

Edit summary for version 29 by hrschueler:
[Haskell] Format improvements (Comments)

Version 28

2018-05-15, 18:34:47

Version 29

2018-05-15, 18:35:35

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Idiom #37 Currying

Transform a function that takes multiple arguments into a function for which some of the arguments are preset.

Extra Keywords
curry
Extra Keywords
curry
Imports
import Data.Ix
Imports
import Data.Ix
Code
curry range
Code
curry range
Comments bubble
range(a,b) = [a..b]
(curry range 1) = \ i -> [1..i]
curry range :: a -> a -> [a]
curry :: ((a, b) -> c) -> a -> b -> c
_"::" means "is of type"

Haskell begins with most functions already curried and allowing partial projection, hence the uncurried range sprang to mind as a notable exception for this illustration.

Data.Ix contains range
Comments bubble
range(a,b) = [a..b]
(curry range 1) = \ i -> [1..i]
curry range :: a -> a -> [a]
curry :: ((a, b) -> c) -> a -> b -> c
"::" means "is of type"

Haskell begins with most functions already curried and allowing partial projection, hence the uncurried range sprang to mind as a notable exception for this illustration.

Data.Ix contains range
Doc URL
http://hackage.haskell.org/package/base/docs/Prelude.html#v:curry
Doc URL
http://hackage.haskell.org/package/base/docs/Prelude.html#v:curry