Hi I'm a Haskell beginner and I'm really lost. This is for my assignment, and it asks me to do something like below using higer order function
Main> mySort (<) [1,5,3,6,4,1,3,3,2]
[1,1,2,3,3,3,4,5,6]
Main> mySort (>) [1,5,3,6,4,1,3,3,2]
[6,5,4,3,3,3,2,1,1]
Main> mySort longerWord [“Hello”, “The”, “a”, “Daniel”, “Declarative”]
[“Declarative”, “Daniel”, “Hello”, “The”, “a”]
First of all, I thought I should make a function that distinguish whether it's < , > or longerWord
checkConditionStr::String->Int
checkConditionStr str
|str=="(<)" =1
|str=="(>)" =2
|str=="longerWord" =3
but the example doesn't have quotation mark (i.e. mysort (<) not my sort"(<)" so here is my first problem. I worte this function but it's not compiling. otherwise is for longerWord
checkCondition::Ordering->Int
checkCondition ord
|ord==(<) =1
|ord==(>) =2
|otherwise =2
secondly I still have difficulty understanding higher order function. would this make sense?
mySort::(String->Int)->[a]->[a]
mySort i list
|i==1 map (sortBy compare) list
|i==2 map (sortBy(flip compare)) list