Lesson 13 of 55
9 mins readPython Function Signatures & Referential Transparency
In Plain English
Functions are pure mathematical mappings in Haskell. Declare explicit type signatures with :: and -> arrows. Because functions are pure, any function call can be replaced with its value (referential transparency).
Deep Dive: How It Works
Type Signatures: add :: Int -> Int -> Int means a function taking an Int and returning a function taking an Int and returning an Int.
Referential Transparency: An expression can be substituted with its resulting value anywhere without altering program behavior.
No Hidden State: Functions cannot modify hidden state or rely on mutable memory.
Core Rules to Remember

Explicit Type Signatures (::): Document and enforce types using :: and -> arrows.

Referential Transparency: Code is predictable and trivially testable because functions produce no side effects.
Live Interactive Example
Hit Run Code to see it liveExplicit Function Signatures
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
Output Console
Click "Run Code" to view the rendered output.
How it works: addThree takes three Ints and returns their sum as an Int.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Define Multiply Three Numbers
Define `multThree :: Int -> Int -> Int -> Int` and implement `multThree a b c = a * b * c`.
Print `"Result: "` followed by `show (multThree 2 3 4)`.
1
2
3
4
5
6
7
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.