Re: WARNING pragmas in `Prelude.undefined` and `Prelude.error`
The idiom of using undefined to replace BangPatterns has a few benefits, which is why it gets used in libraries like bytestring. It doesn't require a language extension and applies a bit nicer in macro expansion because it infects one line of your patterns rather than either mangling all pattern matches or relying on subtleties about whether or not the pattern match earlier was enough to 'forget' the strictness of a later pattern when it isn't strict in a subsequent pattern.
foo !(Bar x) !(Bar y) = ...
foo y w = ... am I strict in w?
foo x y | seq x (seq y False) = undefined
foo (Bar x) (Bar y) = ...
foo y w = ... is definitely strict in w
Other usecases are for working with combinators like sizeOf, alignment, bitSize, bitSizeMaybe, finiteBitSize, or doing things like initializing self-referential IORef structures whenever you do have to tie the knot strictly, etc. In the former cases you can argue that the API should change to take a Proxy, then spend a couple of years driving that change process through, as most of them affect the current language report, but in the latter case you're basically stuck with either embracing momentary partiality and knowledge of lack of escape or working with inaccurately weak types after the structure is initialized, forever.
On Mon, Dec 23, 2019 at 11:30 AM Vilem Liepelt <[hidden email]> wrote:
> On 22 Dec 2019, at 14:15, Zemyla <[hidden email]> wrote:
> The most common legitimate usage for undefined I have is strictness:
> func x y | x `seq` False = undefined
> func x y = ...
> There's nothing else that would go there, and when it's compiled, the reference to undefined disappears.
To add, I know quite a few developers who, during development, use
undefined in place of an "I don't know yet" to get the program
compiling, then perhaps might add an underscore _undefined to determine
Using undefined is perhaps less preferable to using :reload! but it's
quite a bit to type and :r! doesn't work.
On 22/12/19 10:26 pm, Francesco Ariis wrote:
> On Sun, Dec 22, 2019 at 01:44:58PM +0200, Vilem Liepelt wrote:
>> Has there been any discussion about adding WARNING pragmas to `Prelude.undefined` and `Prelude.error`, as done in some custom preludes?
>> I suppose this hasn't been done yet to avoid breaking existing code which makes "legitimate" use of those helpers?
> `undefined` is useful when you want to check types in, e.g. ghcid, without
> writing a function in full.
> With -Wall on, that Warning could become annoying fast.
> Libraries mailing list
> [hidden email] > http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries