[Haskell-cafe] Prelude.head: empty list

Jonas Scholl anselm.scholl at tu-harburg.de
Fri Mar 11 19:07:17 UTC 2016


You mean like this?

  default-extensions:  CPP
  cpp-options:
-Dhead=(foldr(const)(error("head:\x20\x65mpty\x20list\x20in\x20"++__FILE__++":"++show(__LINE__))).(take$1))

Yes, it is a little bit ugly as I am unable to convince cabal to skip
the spaces, so I just avoided them. And build an ugly inline-definition
of head. Maybe having a head' function taking a line number and the file
would help :)

But it should work, if it is not too much broken my my mail-client. The
define should be on one long line.

On 03/11/2016 07:26 PM, Francesco Ariis wrote:
> On Fri, Mar 11, 2016 at 04:56:57PM +0100, Han Joosten wrote:
>> In a rather large program I made some changes, and now I get the runtime
>> error:
>>
>> ampersand.exe: Prelude.head: empty list
>>
>> Of course I know that head is partial, and should be used with care. It is
>> used many times (we have 100+ modules in the program). Is there an elegant
>> way to get some information about where the specific call to head is being
>> made?
>>
>> Thanks!
> 
> I scanned previous replies and didn't see it mentioned, maybe you can
> abuse C preprocessor to shadow `head` and insert a __LINE__ on
> pattern matching []?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160311/73512a17/attachment.sig>


More information about the Haskell-Cafe mailing list