33 lines
819 B
YAML
33 lines
819 B
YAML
title: Functions
|
|
summary: |
|
|
Functions describe a process of turning *inputs* into *outputs*.
|
|
|
|
content: |
|
|
In a purely mathematical setting, functions typically have one input and one
|
|
output, but in functional programming, we can usually get around this either
|
|
by using [tuples][1] or by [currying][2].
|
|
|
|
[1]: page://tuples
|
|
[2]: page://currying
|
|
|
|
exercises:
|
|
|
|
- description: |
|
|
Write a function called `doubleIt` that takes an integer and doubles it.
|
|
|
|
examples:
|
|
ocaml:
|
|
- |
|
|
|
|
grader:
|
|
ocaml:
|
|
style: studentModule
|
|
props:
|
|
interface: |
|
|
val doubleIt : int -> int
|
|
driver: |
|
|
open List
|
|
let () = List.iter
|
|
(fun x -> assert ((doubleIt x) = (x * 2)))
|
|
(List.init 100 (fun x -> x + 1));
|
|
|