I have the following Haskell code using overlapping instances; I tried to implement a function that gives the funcion type as String, or, more generally, does different things for different types of functions:
{-# OPTIONS_GHC -fglasgow-exts #-} {-# LANGUAGE OverlappingInstances, IncoherentInstances #-} module Test where data TypeString = MKTS String instance Show TypeString where show (MKTS s) = s class ShowType bc where theType :: (b -> c) -> TypeString instance ShowType bb where theType _ = MKTS "b -> b" instance ShowType bc where theType _ = MKTS "b -> c" instance ShowType (b, b') c where theType _ = MKTS "(b, b') -> c" class Problem a where showProblem :: a -> TypeString instance Problem (b -> c) where showProblem f = theType f
Haskell shows expected input behavior
> theType (uncurry (+)) (b,b') -> c
But: Can anyone explain the following:
> showProblem (uncurry (+)) b -> c
... and explain how to avoid situations where Haskell selects an overly generic instance ...
source share