I need this function:
blubb :: ??? -> Int
blubb (n :: Int) = n
blubb (n :: Char) = 42
This is how it should work: the function gets an Int and returns it. If the function gets an Char it returns a constant value and the other cases are indifferent.
Because of the type system in Haskell it might be not possible but I need to get this working …
This is what type classes are for:
This overloads
blubbto work on bothInts andChars. The compiler will select the correct one to use based off of the type of the argument.However, be careful that you are not using type classes where you actually wanted an
Either. You may have actually wanted this: