Opened 3 years ago

Last modified 3 years ago

#11967 new feature request

Custom message when showing functions, comparing functions, ...

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Core Libraries Version: 7.10.3
Keywords: CustomTypeErrors Cc: ekmett
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

One of the examples of type errors:

instance TypeError (Text "Cannot 'Show' functions." :$$: 
                    Text "Perhaps there is a missing argument?")
         => Show (a -> b) where
   showsPrec = error "unreachable"

We already have Text.Show.Functions, is there a place in base for this along with Ord (a -> b) instances and co.

Change History (3)

comment:1 Changed 3 years ago by thomie

Cc: ekmett added
Component: CompilerCore Libraries
Keywords: CustomTypeErrors added

Maybe the Core Libraries Committee can answer your question.

comment:2 Changed 3 years ago by Iceland_jack

This can be considered a more general question: would any of the core libraries benefit from custom type errors?

I doubt it is only useful for EDSLs.

comment:3 Changed 3 years ago by Iceland_jack

I'll put this here, from a tweet

instance TypeError (Text "Lists are not numbers!" 
               :$$: Text "Use (++) or (Data.Monoid.<>) instead!") 
  => Num [a]
ghci> "Hello" + " " + "World!"

<interactive>:91:1: error:
    • Lists are not numbers!
      Use (++) or (Data.Monoid.<>) instead!
    • In the expression: "Hello" + " " + "World!"
      In an equation for ‘it’: it = "Hello" + " " + "World!"
Note: See TracTickets for help on using tickets.