42 lines
1 KiB
YAML
42 lines
1 KiB
YAML
title: Functions
|
|
type: concept
|
|
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://fp-tuples
|
|
[2]: page://fp-currying
|
|
|
|
exercises:
|
|
|
|
- name: doubleIt
|
|
style: gradedProgram
|
|
description: |
|
|
Write a function called `doubleIt` that takes an integer and doubles it.
|
|
|
|
graders:
|
|
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));
|
|
|
|
- name: whichIsFunction
|
|
style: multipleChoice
|
|
description: |
|
|
Which of the following can be described as a _function_?
|
|
|
|
graders:
|
|
ocaml:
|
|
style: multipleChoice
|
|
props:
|
|
foo: bar
|