[Haskell-cafe] Prelude.head: empty list
Anatoly Yakovenko
aeyakovenko at gmail.com
Fri Mar 11 16:43:16 UTC 2016
+RTS -xc has worked for me,
https://wiki.haskell.org/Debugging
On Fri, Mar 11, 2016 at 8:13 AM, Jonas Scholl
<anselm.scholl at tu-harburg.de> wrote:
> Which version of GHC are you using? If you are using 7.10.3, you can use
> implicit parameters to get the caller of head (this should be enough to
> narrow down the problem to one module and then add more debugging
> information there). Or you could compile a profiling version of your
> executable and use +RTS -xc (I think), which should print a stack trace
> on any thrown exception (also for exceptions which are later caught).
> Then the last trace should be for head.
>
> To use implicit parameters, you need:
>
> {-# LANGUAGE ImplicitParams #-}
> import GHC.Stack (CallStack, showCallStack)
>
> head' :: (?callStack :: CallStack) => [a] -> a
> head' (x:_) = x
> head' [] = error $ "head': empty list" ++ "\nCallStack:
> " ++ showCallStack ?callStack
>
> Then replace every use of head by head'. If you need more than one stack
> frame, just add (?callStack :: CallStack) to the constraints of the
> calling function and GHC should add another stack frame.
>
> On 03/11/2016 04:56 PM, 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!
>>
>>
>>
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list