[Haskell-beginners] Help with meaningful error message...

aditya siram aditya.siram at gmail.com
Wed Jun 8 00:18:42 CEST 2011


Think about using foldl [1] because it abstracts the general pattern
of recursion you are attempting. So forward routes becomes something
like:

forwardRouter  = foldl (\m row -> ...)

Also you might want to move whatever's in "..." into a new function
that updates the map.

-deech

[1] http://hackage.haskell.org/packages/archive/haskell98/latest/doc/html/List.html#v:foldl



On Tue, Jun 7, 2011 at 4:54 PM, Sean Charles <sean at objitsu.com> wrote:
> On 07/06/11 22:50, aditya siram wrote:
>>
>> I think the parse error is here:
>>
>> forwardRoutes m [] = m
>> forwardRoutes m (row:rows) =
>>  case M.lookup m (row !! 0) of
>>    Just route ->  M.update m (row !! 1):route
>>    Nothing ->  M.insert from []
>>  forwardRoutes m rows<----------------- you probably want to remove this
>> line
>
> If I do that, how does my recursive function call itself again?
>
> I think it is badly broken in the syntax!
> In the last five minutes I have progressed to ...
>
>
> forwardRoutes :: M.Map String [String] -> [Record] -> M.Map
> forwardRoutes m [] = m
> forwardRoutes m (row:rows) =
>  case M.lookup m (row !! 0) of
>    Just route -> M.update m (row !! 1):route
>    Nothing    -> M.insert (row!!0) []
>  forwardRoutes m rows
>
> but I think it ought to be...
>
>
> forwardRoutes :: M.Map String [String] -> [Record] -> M.Map
> forwardRoutes m [] = m
> forwardRoutes m (row:rows) =
>  case M.lookup m (row !! 0) of
>    Just route -> forwardRoutes (M.update m (row !! 1):route) rows
>    Nothing    -> forwardRoutes (M.insert (row!!0) []) rows
>
> Anybody! LOL :)
>
>
>>
>> -deech
>>
>>
>> On Tue, Jun 7, 2011 at 4:44 PM, Sean Charles<sean at objitsu.com>  wrote:
>>>
>>> OK, I am losing enough hair and accruing follicular damage more than I
>>> can
>>> take tonight, what is wrong, what have I done that is stupid and wrong
>>> etc...
>>>
>>> called:
>>>  let routes = forwardRoutes M.empty csvdata  -- [Record] from Text.CSV
>>>
>>> implemented:
>>>
>>> forwardRoutes m [] = m
>>> forwardRoutes m (row:rows) =
>>>  case M.lookup m (row !! 0) of
>>>    Just route ->  M.update m (row !! 1):route
>>>    Nothing ->  M.insert from []
>>>  forwardRoutes m rows
>>>
>>>
>>> error: scread.hs:101:2: parse error on input `forwardRoutes'
>>>
>>> Um yeah, thanks, that's really helping me figure it out.
>>>
>>> All I wanted to do was build a map of keys and values where each value is
>>> a
>>> list that gradually accumulates(!) every row that ends at (!!1)  from the
>>> same location (!!0) of my spreadsheet. I started off zipping with 'repeat
>>> []' and stuff but I just want to know what I have done to annoy the
>>> compiler
>>> enough to want to taunt me with that message.
>>>
>>> And, on the verge of posting I think the above code won't work anyway
>>> because I am not passing the new Map from 'insert' through.......
>>>
>>> ARGH!
>>> :(
>>>
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>
>



More information about the Beginners mailing list