Skip to content

Commit 4998480

Browse files
committed
lf
1 parent 04d9bcf commit 4998480

19 files changed

+334
-242
lines changed

chapter10.1.idr

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ showList xs = "[" ++ show' xs ++ "]" where
99
show' : List a -> String
1010
show' Nil = ""
1111
show' (x :: Nil) = show x
12-
show' (x :: xs) = show x ++ ", " ++ show' xs
12+
show' (x :: xs) = show x ++ ", " ++ show' xs
1313

1414
data ListLast : List a -> Type where
1515
Empty : ListLast []
1616
NonEmpty : (xs : List a) -> (x : a) -> ListLast (xs ++ [x])
1717

1818
describeHelper : (input : List Int) -> (form : ListLast input) -> String
1919
describeHelper [] Empty = "Empty"
20-
describeHelper (xs ++ [x]) (NonEmpty xs x)= "Non-empty, initial portion = " ++ show xs
20+
describeHelper (xs ++ [x]) (NonEmpty xs x)= "Non-empty, initial portion = " ++ show xs
2121

2222
listLast : (xs : List a) -> ListLast xs
2323
listLast [] = Empty
24-
listLast (x :: xs) = case listLast xs of
24+
listLast (x :: xs) = case listLast xs of
2525
Empty => NonEmpty [] x
2626
(NonEmpty ys y) => NonEmpty (x :: ys) y
2727

2828
describeListEnd : List Int -> String
2929
describeListEnd xs with (listLast xs)
3030
describeListEnd _ | Empty = "Empty"
31-
describeListEnd _ | (NonEmpty ys x) ="Non-empty, initial portion = " ++ show ys
31+
describeListEnd _ | (NonEmpty ys x) ="Non-empty, initial portion = " ++ show ys
3232

3333
covering myReverse : List a -> List a
3434
myReverse xs with (listLast xs)
@@ -39,14 +39,14 @@ data SplitList : List a -> Type where
3939
SplitNil : SplitList []
4040
SplitOne : SplitList [x]
4141
SplitPair : (lefts : List a) -> (rights : List a) -> SplitList (lefts ++ rights)
42-
42+
4343
splitList : (input : List a) -> SplitList input
4444
splitList input = splitListHelp input input
4545
where
4646
splitListHelp : List a -> (input : List a) -> SplitList input
4747
splitListHelp _ [] = SplitNil
4848
splitListHelp _ [x] = SplitOne
49-
splitListHelp (_ :: _ :: counter) (item :: items) =
49+
splitListHelp (_ :: _ :: counter) (item :: items) =
5050
case splitListHelp counter items of
5151
SplitNil => SplitOne
5252
SplitOne {x} => SplitPair [item] [x]
@@ -57,13 +57,13 @@ partial mergeSort : Ord a => List a -> List a
5757
mergeSort xs with (splitList xs)
5858
mergeSort [] | SplitNil = []
5959
mergeSort [x] | SplitOne = [x]
60-
mergeSort (lefts ++ rights) | (SplitPair lefts rights) = merge (mergeSort lefts) (mergeSort rights)
60+
mergeSort (lefts ++ rights) | (SplitPair lefts rights) = merge (mergeSort lefts) (mergeSort rights)
6161

6262
data TakeN : List a -> Type where
6363
Fewer : TakeN xs
6464
Exact : (n_xs : List a) -> TakeN (n_xs ++ rest)
6565

66-
takeN : (n : Nat) -> (xs : List a) -> TakeN xs
66+
takeN : (n : Nat) -> (xs : List a) -> TakeN xs
6767
takeN Z xs = Exact []
6868
takeN (S k) [] = Fewer
6969
takeN (S k) (x :: xs) with (takeN k xs)
@@ -75,18 +75,18 @@ groupByN n xs with (takeN n xs)
7575
groupByN n xs | Fewer = [xs]
7676
groupByN n (n_xs ++ rest) | (Exact n_xs) = n_xs :: groupByN n rest
7777

78-
half : Nat -> Nat
78+
half : Nat -> Nat
7979
half Z = Z
8080
half (S Z) = Z
8181
half (S (S x)) = S (half x)
8282

83-
halves : List a -> (List a, List a)
84-
halves xs =
83+
halves : List a -> (List a, List a)
84+
halves xs =
8585
let mid = half $ length xs
8686
taken = takeN mid xs
87-
in case taken of
87+
in case taken of
8888
Fewer => ([], xs)
8989
(Exact n_xs {rest}) => (n_xs, rest)
9090

9191
main : IO ()
92-
main = pure ()
92+
main = pure ()

chapter10.2.idr

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@ mergeSort : Ord a => List a -> List a
1010
mergeSort xs with (splitRec xs)
1111
mergeSort [] | SplitRecNil = []
1212
mergeSort [x] | SplitRecOne = [x]
13-
mergeSort (lefts ++ rights) | (SplitRecPair lrec rrec) = merge (mergeSort lefts | lrec) (mergeSort rights | rrec)
13+
mergeSort (lefts ++ rights) | (SplitRecPair lrec rrec) = merge (mergeSort lefts | lrec) (mergeSort rights | rrec)
1414

1515
equalSuffix : Eq a => List a -> List a -> List a
1616
equalSuffix xs ys with (snocList xs)
1717
equalSuffix xs ys | recx with (snocList ys)
1818
equalSuffix _ _ | Empty | Empty = []
1919
equalSuffix _ _ | (Snoc _) | Empty = []
2020
equalSuffix _ _ | Empty | (Snoc _) = []
21-
equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc recx) | (Snoc recy) =
21+
equalSuffix (xs ++ [x]) (ys ++ [y]) | (Snoc recx) | (Snoc recy) =
2222
if x /= y then [] else (equalSuffix xs ys | recx | recy) ++ [x]
2323

2424
mergeSortV : Ord a => Vect n a -> Vect n a
2525
mergeSortV xs with (splitRec xs)
2626
mergeSortV [] | SplitRecNil = []
2727
mergeSortV [x] | SplitRecOne = [x]
28-
mergeSortV (lefts ++ rights) | (SplitRecPair lrec rrec) = merge (mergeSortV lefts | lrec) (mergeSortV rights | rrec)
29-
28+
mergeSortV (lefts ++ rights) | (SplitRecPair lrec rrec) = merge (mergeSortV lefts | lrec) (mergeSortV rights | rrec)
29+
3030
toBinary : Nat -> String
31-
toBinary k with (halfRec k)
31+
toBinary k with (halfRec k)
3232
toBinary Z | HalfRecZ = "0"
3333
toBinary (n + n) | (HalfRecEven rec) = (toBinary n | rec) ++ "0"
3434
toBinary (S (n + n)) | (HalfRecOdd rec) = (toBinary n | rec) ++ "1"
3535

36-
palindrome : List Char -> Bool
37-
palindrome s with (vList s)
36+
palindrome : List Char -> Bool
37+
palindrome s with (vList s)
3838
palindrome [] | VNil = True
3939
palindrome [x] | VOne = True
4040
palindrome (x :: (xs ++ [y])) | (VCons rec) = x == y && (palindrome xs | rec)
4141

4242
main : IO ()
43-
main = print $ mergeSort [1,4,5,2,3,4,7]
43+
main = print $ mergeSort [1,4,5,2,3,4,7]

chapter10.3/DataStore.idr

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ empty = MkData 0 []
2424

2525
export
2626
addToStore : (value : SchemaType schema) -> (store : DataStore schema) -> DataStore schema
27-
addToStore value (MkData _ items) = MkData _ (value :: items)
27+
addToStore value (MkData _ items) = MkData _ (value :: items)
2828

2929
public export
3030
data StoreView : DataStore schema -> Type where
3131
SNil : StoreView empty
3232
SAdd : (rec : StoreView store) -> StoreView (addToStore value store)
33-
33+
3434
storeViewHelp : (items : Vect size (SchemaType schema)) -> StoreView (MkData size items)
3535
storeViewHelp [] = SNil
3636
storeViewHelp (val :: xs) = SAdd (storeViewHelp xs)
3737

3838
export
3939
storeView : (store : DataStore schema) -> StoreView store
40-
storeView (MkData size items) = storeViewHelp items
40+
storeView (MkData size items) = storeViewHelp items

chapter10.3/TestStore.idr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import DataStore
22

33
testStore : DataStore (SString .+. SString .+. SInt)
4-
testStore =
4+
testStore =
55
addToStore ("Mercury", "Mariner 10", 1974) (
66
addToStore ("Venus", "Venera", 1961) (
77
addToStore ("Uranus", "Voyager 2", 1986)(
@@ -14,9 +14,9 @@ testStore =
1414
listItems : DataStore schema -> List (SchemaType schema)
1515
listItems input with (storeView input)
1616
listItems empty | SNil = []
17-
listItems (addToStore value store) | (SAdd rec) = value :: listItems store | rec
17+
listItems (addToStore value store) | (SAdd rec) = value :: listItems store | rec
1818

1919
getValues : DataStore (SString .+. val_schema) -> List (SchemaType val_schema)
2020
getValues input with (storeView input)
2121
getValues empty | SNil = []
22-
getValues (addToStore (MkPair _ value) store) | (SAdd rec) = value :: listItems store | rec
22+
getValues (addToStore (MkPair _ value) store) | (SAdd rec) = value :: listItems store | rec

chapter11.1.idr

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Data.Bits
99

1010
data InfList : Type -> Type where
1111
(::) : (value : elem) -> Inf (InfList elem) -> InfList elem
12-
13-
12+
13+
1414
%name InfList xs, ys, zs
1515

1616
countFrom : Integer -> InfList Integer
@@ -32,8 +32,8 @@ instance Show Face where
3232
show Heads = "Heads"
3333
show Tails = "Tails"
3434

35-
isOdd : Int -> Bool
36-
isOdd value =
35+
isOdd : Int -> Bool
36+
isOdd value =
3737
let onePattern = bitAt (the (Fin 1) 0)
3838
in ((intToBits (cast value)) `Data.Bits.and` onePattern) == onePattern
3939

@@ -42,4 +42,4 @@ coinFlips : Stream Int -> Stream Face
4242
coinFlips (value :: xs) = (if isOdd value then Heads else Tails) :: coinFlips xs
4343

4444
main : IO ()
45-
main = print $ take 10 (coinFlips [1..])
45+
main = print $ take 10 (coinFlips [1..])

chapter11.2.idr

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ data InfIO : Type where
1616
data Fuel = Dry | More (Lazy Fuel)
1717

1818
loopPrint : String -> InfIO
19-
loopPrint msg = Do (putStrLn msg) (\_ => loopPrint msg)
19+
loopPrint msg = Do (putStrLn msg) (\_ => loopPrint msg)
2020

2121
run : Fuel -> InfIO -> IO ()
22-
run (More fuel) (Do c f) =
23-
do
22+
run (More fuel) (Do c f) =
23+
do
2424
res <- c
2525
run fuel (f res)
2626
run Dry p = putStrLn "Out of fuel"
2727

2828
quiz : Stream Int -> (score : Nat) -> InfIO
29-
quiz (num1 :: num2 :: nums) score =
30-
do
29+
quiz (num1 :: num2 :: nums) score =
30+
do
3131
putStrLn ("Score so far: " ++ show score)
3232
putStr (show num1 ++ "*" ++ show num2 ++ "? ")
3333
answer <- getLine
34-
if (cast answer == num1 * num2)
35-
then
36-
do
34+
if (cast answer == num1 * num2)
35+
then
36+
do
3737
putStrLn "Correct!"
3838
quiz nums (score + 1)
39-
else
40-
do
39+
else
40+
do
4141
putStrLn ("Wrong, the answer is " ++ show (num1 * num2))
42-
quiz nums score
42+
quiz nums score
4343

4444
covering
4545
forever : Fuel
4646
forever = More forever
4747

4848
totalREPL : (prompt : String) -> (action : String -> String) -> InfIO
49-
totalREPL prompt action =
50-
do
49+
totalREPL prompt action =
50+
do
5151
putStr prompt
5252
input <- getLine
5353
putStr $ action input
@@ -56,4 +56,4 @@ totalREPL prompt action =
5656

5757
covering
5858
main : IO ()
59-
main = run forever (quiz [1..] 0)
59+
main = run forever (quiz [1..] 0)

0 commit comments

Comments
 (0)