I just wrote this function, wondering what would happen if I omitted the Nil case, and noticed that scalac gives me a warning: def printList[String](list: List[String]) { list match { case head :: tail => { println(head) printList(tail) } //case Nil => println("Done") } } Warning: match may not be...

I'm reading Functional Programming in Scala, and in chapter 04 the authors implement Option on their own. Now, when defining the function getOrElse they use an upper bound to restrict the type of A to a supertype (if a understood correctly) So, the definition goes: sealed trait Option[+A] { def...

I am experimenting with some rather complex type-level calculations. There, I have some type tags (say, A, B, and C), and functions working on them, which are represented by implicit witnesses with path-dependent result types: class A class B class C trait F1[T] { type result } trait F2[T] {...

I have been implementing kadane's algorithm in haskell, AFAIK it is working correctly kadane' :: (Ord a, Num a) => [a] -> a kadane' xs = head$ foldl maxsub [0,0] xs maxsub :: (Ord a, Num a) => [a] -> a -> [a] maxsub x y | last(x)+y > head(x)...

Suppose: import Data.Int (Int64) data Unknown class Meh a where meh :: a -> String instance Meh Int64 where meh = show instance Meh Unknown where meh _ = "Unknown" It is obvious that meh can only take either an Int64 or an Unknown. But we all know that meh...