Skip to content

Commit

Permalink
new Koans for tuples and HoF
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan de Muijnck-Hughes committed Jun 4, 2014
1 parent 992ac33 commit 23d3359
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Koans/07-Tuples.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Koans.Tuples

-- Complete the following functions

firstPair : Bool
firstPair = ?fillme1 == fst ("First", "Pair")

secondPair : Bool
secondPair = ?fillme2 == snd ("Second", "Pair")

whatAmI : Vect 5 (Int, Bool)
whatAmI = ?fillme3

ws : Vect 5 String
ws = ["zip", "a", "dee", "doo", "dah"]

is : Vect 5 Int
is = ?fillme4

myFirstZip : Bool
myFirstZip = zip ws is == ?fillme5

whatIsMyResult : Bool
whatIsMyResult = ?fillme6 == Vect.zipWith (+) is is
51 changes: 51 additions & 0 deletions Koans/08-HigherOrderFunctions.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module Koans.HigherOrderFunctions

-- Complete these functions

-- Maps are used to map a function to elements in a list.
myFirstMap : Bool
myFirstMap = ?fillme1 == map (2*) [1..4]

mySecondMap : Bool
mySecondMap = [1, 4, 9, 16, 25] == map ?fillme2 [1..5]

myThirdMap : Bool
myThirdMap = [25, 16, 9, 4, 1] == map ?fillme3 [1..5]

-- Folds are used to combine elements in a list from start to finish using a function.
myFirstFold : Bool
myFirstFold = foldl (+) 0 [1..4] == ?fillme4

mySecondFold : Bool
mySecondFold = 5 == foldl ?fillme5 5 [1..4]


-- Scans are like fold but you see the intermediate results, and then the result.
myFirstScan : Bool
myFirstScan = scanl (max) 5 [1,2,3,4] == ?fillme6

mySecondScan : Bool
mySecondScan = scanl ?fillme7 5 [1,2,10,1] == [5,5,5,10,10]

myThirdScan : Bool
myThirdScan = scanl (/) 64 [4,2,4] == ?fillme8


-- TODO Add examples for scanr and foldr


-- You can filter things as well.

xs : List Int
xs = [1,2,3,4,5,6,7,8,9,10]

myFirstFilter : Bool
myFirstFilter = filter (>5) xs == ?fillme15

mySecondFilter : Bool
mySecondFilter = filter ?fillme16 [10,20,30,40,50,60,70,80,90,100] == xs

-- You can combine functions as well

myFirstCombi : Bool
myFirstCombi = ["bang", "boom", "bang", "boom", "bang"] == map ?fillme17 (filter ?fillme18 xs)

0 comments on commit 23d3359

Please sign in to comment.