Tracking down errors in Haskell

haskell

Solution

you can get the string that caused the parse error by importing `Debug.Trace` and changing your call

import Debug.Trace (trace)

--change
myRead s = read s
--to 
myRead s = trace s (read s)
--or 
myRead s = trace (take 100 s) (read s)

Problem

How can I get more information about where a Haskell error has occurred? For example, yesterday I was working on a Haskell program that parses an input file, transforms the data and then prints out reporting information. At one point, I ran "main" and got back ``` *** Prelude.read: parse error ``` with no other information. Fortunately, I knew I was calling read in only one place and was able to fix it, but for the future: - Is it possible to get a backtrace or a line number for errors like these? - Is it possible to get the actual data that triggered the error, i.e. the string that caused the parse error? Thanks! Edit Using GHC.

Original source

Related problems