I want to have an overloaded function in Haskell.
{-# LANGUAGE FlexibleInstances #-}
class Foo a where
foo :: a
instance Foo (String -> Int) where
foo = length
instance Foo String where
foo = "world"
However, such an overload is very poorly related to type ambiguity. print $ foo "hello"will lead to an error, but it print $ length "hello"works fine. However, provided that my list of instances is corrected, there should be no technical reason why Haskell cannot understand that the only instance foo :: String -> ais foo :: String -> Int. Can I make Haskell for this implementation?
source
share