Type Inference in Haskell v. Scala -
given following code: prelude> let f x = if (x) 55 else "foo" why compiler num [char] ? <interactive>:2:23: no instance (num [char]) arising literal `55' in expression: 55 in expression: if (x) 55 else "foo" in equation `f': f x = if (x) 55 else "foo" however, in scala, find least-upper bound of 55 , "foo" , any : scala> def f(x: boolean) = if (x) 55 else "foo" f: (x: boolean)any import scala.reflect.runtime.universe._ scala> lub( list[type]( typeof[int], typeof[string] ) ) res4: reflect.runtime.universe.type = what's key difference between haskell's , scala's type inference? you can add instance num [char] in haskell, if that's want: {-# language flexibleinstances #-} import data.function (on) import data.composition ((.:)) -- cabal install composition helper :: (integer -> integer -> integer) -> (string -> string -> string) helper o