liveBook · Manning

Function type

As explained in Learn Haskell by Example

A function type specifies the input and output types of a function value.

A function type specifies the input and output types of a function value. Haskell writes a unary function type as Int -> Int: the function maps an Int to another Int. section 2.2.3

Function types resemble the functions they describe. A function written as an anonymous lambda can be named, then given a signature that documents the value it accepts and produces. section 2.2.3

Read multi-argument function types from left to right:

  • add :: Int -> Int -> Int describes a function taking an Int and producing another function that takes an Int and produces an Int. section 2.2.3
  • Parentheses make the nested structure explicit: Int -> (Int -> Int). Haskell commonly omits them as syntactic sugar. section 2.2.3
  • The final type is conventionally called the return type, while earlier types describe the arguments. section 2.2.3
square :: Int -> Int
square = \x -> x * x

Use the complete square definition to connect a lambda expression with its function type. section 2.2.3

add :: Int -> Int -> Int
add = \x -> \y -> x + y

Compare the curried add function with its two-argument lambda form. section 2.2.3

Types also expose constraints imposed by operators. Although (*) works with numeric values, multiplying an Int by a Double produces a type error because both operands must share the required type. section 2.2.4

Character rotation

An encryption routine can describe a character-rotation function as Int -> Char -> Char: an offset is supplied first, followed by a character, producing a character. section 2.2.4

Typed functions in a synthesizer

An Oscillator can wrap an Event -> Signal function. Different oscillators reuse the same shape while varying their waveform and ADSR parameters. section 10.3.2

How Learn Haskell by Example covers it

How deep it goes
Explains unary and curried function types, lambda notation, syntactic sugar, and operator-driven type errors without covering deeper type-system internals.
Examples
Uses square and add definitions, mixed Int and Double multiplication, character rotation, and Event-to-Signal oscillators.
What it assumes
Builds from anonymous functions and simple arithmetic before introducing multi-argument signatures and nested function types.
What you can do after
Evaluate and write Haskell signatures for unary, multi-argument, and function-valued definitions while diagnosing simple type mismatches.
How it connects
Connects function types with lambda abstraction, currying, type errors, encryption, and event-driven signal processing.

Also explained in

Compare how 4 books explain function type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.