Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: exceptions and stacks (Emmanuel Touzery)
2. Re: exceptions and stacks (Karol Samborski)
3. Re: exceptions and stacks (Emmanuel Touzery)
----------------------------------------------------------------------
Message: 1
Date: Tue, 6 Nov 2012 23:15:19 +0100
From: Emmanuel Touzery <[email protected]>
Subject: Re: [Haskell-beginners] exceptions and stacks
To: [email protected]
Message-ID:
<CAC42RekiuHTy053As-MVuuJKmD_juSGHseNBhtW=g0gwp+z...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
so I have found the culprit, by defining this function:
Import Debug.Trace
headMarker :: String -> [a] -> a
headMarker marker [] = trace marker (head [])
headMarker _ array = head array
and replacing calls to head to "headMarker "XX"", "headmarker "YY"" and so
on.
it works but I would really rather have a compiler/runtime based solution
which would not force me to modify my code to track the bug (and would be
simpler to use in case the problem comes from a library).
If anybody has an idea what I did wrong with the -xc and the -RTS I'm all
ears... I'd love to test it and find out how to make that work reliably.
Emmanuel
On Tue, Nov 6, 2012 at 10:50 PM, Emmanuel Touzery <[email protected]>wrote:
> you mean in combination with the RTS/profiling trick?
> If I must do something like that, I'll just mark my code with debug lines
> or code the else situations (like making a headMarker with an extra
> parameter "String marker" and it will output the marker on stdoud if the
> array is empty), seems less work...
>
> I was really hoping being able to fix it without having the modify the
> code, it's disappointing, I think.
>
>
> On Tue, Nov 6, 2012 at 9:47 PM, Christian Maeder <[email protected]
> > wrote:
>
>> Usually, these head calls are in your code. Do "fgrep head" on your
>> sources and replace all suspicious occurrences. Use "let h : _ = l in ..."
>> and "h" instead of "head l" for proper positions.
>>
>> HTH Christian
>>
>> Am 06.11.2012 12:44, schrieb Emmanuel Touzery:
>>
>> Hello,
>>>
>>> I'm getting really frustrated by error handling in haskell. By this
>>> I mean "assert"-like errors. Which means, something that should never
>>> happen, happens. This will happen in the development and deployment of
>>> software of any size.
>>> When coding the feature you'll say, I don't need to handle the
>>> "Nothing" case, because it will never happen, or almost never, and this
>>> is not critical production software.
>>>
>>> But if one day it happens you find yourself with a several thousand
>>> lines program and all you have to debug is the input data (most of the
>>> time anyway, sometimes not even that) and this error message (for
>>> instance):
>>>
>>> *** Exception: Prelude.head: empty list
>>>
>>> And you don't know even, did you call "head" or maybe a library you
>>> are using called it.
>>>
>>> This is really poor compared to what Java, python and others
>>> offers. I can understand that it's difficult to provide a stack trace,
>>> especially with lazy evaluation, but at least the function name and
>>> maybe a line number... Actually I don't know why it would be so
>>> difficult to also give me the values of the parameters of the
>>> function... using print and if it's a pure function it intuitively
>>> doesn't seem difficult.
>>>
>>> I've tried ghci with :trace and ":set -fbreak-on-exception" and I
>>> got nowhere. It breaks in things which are not important (I have no idea
>>> where it breaks, it claims an exception was thrown, maybe but not in my
>>> code and it never reaches my code for sure). After hitting ":continue"
>>> many times, I get to my exception and there I didn't manage to get
>>> useful information (:hist never printed me anything).
>>>
>>> But I would like not to have to use ghci at all. And to avoid
>>> having to write all over the place in my code these "else" and case
>>> situations for things I assume are impossible (these are cases I would
>>> not write in other modern languages).
>>>
>>> This is a feature for which I would be ready to pay a 50% speed
>>> penalty and 50% memory use penalty.
>>>
>>> I understand if it's the haskell way of writing all those else
>>> clauses... But I think in that case it really makes it compare
>>> negatively to other languages. It would be a real minus in my opinion
>>> (including to code readability).
>>>
>>> I have read (quickly) those but didn't find the solution there:
>>> http://www.haskell.org/ghc/**docs/7.0.1/html/users_guide/**
>>> ghci-debugger.html<http://www.haskell.org/ghc/docs/7.0.1/html/users_guide/ghci-debugger.html>
>>> http://book.realworldhaskell.**org/read/error-handling.html<http://book.realworldhaskell.org/read/error-handling.html>
>>>
>>> Any advice will be welcome! I really hope I missed something.
>>>
>>> Emmanuel
>>>
>>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121106/bd4d0f80/attachment-0001.htm>
------------------------------
Message: 2
Date: Wed, 7 Nov 2012 08:51:03 +0100
From: Karol Samborski <[email protected]>
Subject: Re: [Haskell-beginners] exceptions and stacks
To: Emmanuel Touzery <[email protected]>
Cc: [email protected]
Message-ID:
<CACe2dTttnHnpFS8mL1dknxMEBiGzYBSF=annpdhjsou25cn...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi Emmanuel!
Have you looked at
http://hackage.haskell.org/packages/archive/loch-th/0.2.1/doc/html/Debug-Trace-LocationTH.html
? With the loch-th package you can write your own head function like
this:
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Debug.Trace.LocationTH
myHead a = $check $ head a
and then something like myHead ([] :: [Char]) will print something like this:
test: test.hs:21:12-17: Prelude.head: empty list
In docs there is another useful function $failure that is "a
location-emitting error call".
Hope that helps.
------------------------------
Message: 3
Date: Wed, 07 Nov 2012 09:03:38 +0100
From: Emmanuel Touzery <[email protected]>
Subject: Re: [Haskell-beginners] exceptions and stacks
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hello,
that is very interesting.
on top of that, this library also offers an "assert" function,
which will throw an exception with location in the source code if the
assert condition is false.
so i will definitely consider this. i would really rather compiler
support but... That's probably the next best thing.
Emmanuel
On 7.11.2012 8:51, Karol Samborski wrote:
> Hi Emmanuel!
>
> Have you looked at
> http://hackage.haskell.org/packages/archive/loch-th/0.2.1/doc/html/Debug-Trace-LocationTH.html
> ? With the loch-th package you can write your own head function like
> this:
>
> {-# LANGUAGE TemplateHaskell #-}
> module Main where
>
> import Debug.Trace.LocationTH
>
> myHead a = $check $ head a
>
> and then something like myHead ([] :: [Char]) will print something like this:
> test: test.hs:21:12-17: Prelude.head: empty list
>
> In docs there is another useful function $failure that is "a
> location-emitting error call".
>
> Hope that helps.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 53, Issue 11
*****************************************