>       take :: Int -> [a] -> [a]
>If you want to define your own take
>       mytake :: Show a => Int -> [a] -> [a]
>that's fine, but it's a different function.
>
>And for (head []) there's really no useful info to hand. So I'm stumped.

Although you can't show the value (because there isn't one), you can
at least show the type of the expression:

    class ShowType a where
        showType :: a -> String
    instance ShowType a => ShowType [a] where
        showType xs = "[" ++ showType x ++ "]"
                        where ~(x:_) = xs

Then

    myhead :: ShowsType a => [a] -> a
    myhead xs@[] = error ("myhead of empty list at type "++ showType xs)
    myhead (x:_) = x

which, like "mytake", is a different function from the one defined
in the Prelude, but might give you enough info to help track down
the error.

Regards,
    Malcolm


Reply via email to