-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd3.hs
More file actions
32 lines (24 loc) · 679 Bytes
/
d3.hs
File metadata and controls
32 lines (24 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances,
UndecidableInstances
#-}
import Prelude hiding (succ)
-- Define some type-level numbers (inductively)
data Z -- Zero
data S n -- Successor of some other number
-- Define a succ "function"
-- mySucc :: Int -> Int
class Succ i1 i | i1 -> i
-- Implement our "function" inductively
-- mySucc n = n + 1
-- Base case: succ 0
instance Succ Z (S Z)
-- Inductive case: succ S n
instance Succ (S x) (S (S x))
-- Tie our "function" to a value so it can be type-checked
succ :: Succ i1 i => i1 -> i
succ = const undefined
-- What is:
-- :type succ (undefined::Z)
-- :type succ (succ (undefined::(S Z)))