Skip to content

Code that won't ever be executed should not give rise to constraints

In the code

a x = let b = show x in 5, 

ghci derives:

a :: (Show a, Num t) => a -> t, 

which is correct, but I think the rules should be slightly altered, since in reality giving something to a which is not an instance of Show wouldn't be a problem, since it's not used in the first place.

One important application of this is testing a general data structure for one specific element type with assertions in the the general code and having a switch to turn generic and non-generic mode on and off. Unfortunately, this approach doesn't work today, since all kinds of constraints that are essentially part of the debugging process get added. Since deciding whether a certain variable is used is very easy in this setting(for example CPP macros that expand into "if debugging", where debugging will have a constant value. (I don't expect you to solve the Halting Problem).

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information