I am new and naive to scala. Just know how to define a function type such as Set here(only as an example).
type Set = Int => Boolean
def set(i: Int): Set = n => n == i
def contains(s: Set, i: Int) = s(i)
I also read the wiki of language-agnostic function type. It seems C#,C,Haskel also have the similiar grammer. http://en.wikipedia.org/wiki/Function_type.
My question is in which case you prefer to define one of this kind of abstract type function and use it,
And no other choice to reach the same target? Comparing to directly define a concrete method using def
Or I can loose the requirement, to say using this function type, I can make the code looks much better. So that I can know more about function type.
Here my main interested part is type Set = Int => Boolean
,when you want to abstract it out? I am looking for real life use case, and how to implement it in concrete method in scala grammer.
For example, this one is a bit complex.
type Set2 = (Int,Int,String) => (Boolean => Int) => (Boolean => Int).
I know it's called higher-kinded types. The grammer itself is indeed meaningful. But I just need more plain real life examples to scala beginners.
I found this answer describing for it. What is a higher kinded type in Scala?
But it still looks a bit obscure for me. I prefer plain answer for beginner. It seems like the function itself didn't require anything except the parameter and result type to the implementation mentod. For example, if the result (Boolean) doesn't come from parameter (Int) ,it still compiles.
def set(i: Int): Set1 = aa => new Date().getDate() == i
Am I unstanding it right?
Let me know why this question is not clear or bad, so I can improve it,Sir!