-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC4S2.idr
31 lines (25 loc) · 980 Bytes
/
C4S2.idr
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
import Data.Vect
data PowerSource = Petrol | Pedal | Electric
data Vehicle : PowerSource -> Type where
Bicycle : Vehicle Pedal
Unicycle : Vehicle Pedal
Motorcycle : (fuel : Nat) -> Vehicle Petrol
Car : (fuel : Nat) -> Vehicle Petrol
Bus : (fuel : Nat) -> Vehicle Petrol
total wheels : Vehicle power -> Nat
wheels Bicycle = 2
wheels Unicycle = 1
wheels (Motorcycle fuel) = 2
wheels (Car fuel) = 4
wheels (Bus fuel) = 4
total refuel : Vehicle Petrol -> Vehicle Petrol
refuel (Motorcycle fuel) = Motorcycle 50
refuel (Car fuel) = Car 100
refuel (Bus fuel) = Bus 200
total vectTake : (m: Fin n) -> Vect n a -> Vect (cast m) a
vectTake FZ _ = []
vectTake (FS k) (x :: xs) = x :: vectTake k xs
sumEntries : Num a => (pos : Integer) -> Vect n a -> Vect n a -> Maybe a
sumEntries {n} pos xs ys = case integerToFin pos n of
Nothing => Nothing
Just i => Just ((Vect.index i xs) + (Vect.index i ys))