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:  How to interpret the definition of   MonadState
      (Daniel Fischer)
   2.  Help with meaningful error message... (Sean Charles)
   3. Re:  Help with meaningful error message... (aditya siram)
   4. Re:  Help with meaningful error message... (Sean Charles)
   5. Re:  Help with meaningful error message... (aditya siram)
   6. Re:  Help with meaningful error message... (Daniel Fischer)
   7. Re:  Function definition order and performance
      (Arlen Christian Mart Cuss)
   8. Re:  Function definition order and performance (Daniel Fischer)


----------------------------------------------------------------------

Message: 1
Date: Tue, 7 Jun 2011 22:21:47 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] How to interpret the definition of
        MonadState
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="us-ascii"

On Tuesday 07 June 2011, 17:35:45, [email protected] wrote:
> Does that mean it's ghc specific, i.e. not in Haskell 98 / 2010?

It's not in haskell98 or haskell2010, but I think hugs also supports 
functional dependencies (however, hugs is pretty much dead, last release 
September 2006). I don't know which extensions other compilers support, not 
even which of them should be considered alive.



------------------------------

Message: 2
Date: Tue, 07 Jun 2011 22:44:54 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] Help with meaningful error message...
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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!
:(





------------------------------

Message: 3
Date: Tue, 7 Jun 2011 16:50:34 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Help with meaningful error message...
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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


-deech


On Tue, Jun 7, 2011 at 4:44 PM, Sean Charles <[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

Message: 4
Date: Tue, 07 Jun 2011 22:54:18 +0100
From: Sean Charles <[email protected]>
Subject: Re: [Haskell-beginners] Help with meaningful error message...
To: aditya siram <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

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<[email protected]>  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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>




------------------------------

Message: 5
Date: Tue, 7 Jun 2011 17:18:42 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Help with meaningful error message...
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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 <[email protected]> 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<[email protected]> ?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
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>
>



------------------------------

Message: 6
Date: Wed, 8 Jun 2011 00:31:36 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Help with meaningful error message...
To: [email protected]
Cc: Sean Charles <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="us-ascii"

On Tuesday 07 June 2011, 23:54:18, Sean Charles 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

Much closer. Now you have a recursion and it can be parsed. The error will 
now arise in type-checking.

You've flipped the arguments in the lookup.

In the `Just' case, (M.update m (row !! 1):route) is parsed as

(M.update m (row !! 1)) : route

which is a list, not a map. You'll need to parenthesize thus:
((row !! 1) : route)

However,

Prelude> :t Data.Map.update
Data.Map.update
  :: Ord k =>
     (a -> Maybe a) -> k -> Data.Map.Map k a -> Data.Map.Map k a

so there's more to change in that branch. It seems that if (row !! 0) is a 
key in the map, you want to modify the associated value by prepending
(row !! 1) to it. That would be achieved by

(M.update (\_ -> Just ((row !! 1):route)) (row !! 0) m)

But you don't use the value associated to the key here [you could, but 
you've already looked that up before], so update is probably the wrong 
function here, try

(M.insert (row !! 0) ((row !! 1) : route) m)

In the `Nothing' branch, you've omitted the map in which to insert.


forwardRoutes m (row@(h:t):rows) =
  case M.lookup h m of
    Just route -> forwardRoutes (M.insert h (head t:route) m) rows
    Nothing -> forwardRoutes (M.insert h [] m) rows

would do what I think you want.

But it'd better be written as a fold,

forwardRoutes m rows = Data.List.foldl' update1 m rows
-- you can leave off the arguments if you wish

Now, update1 is the single-row update function, e.g.

update1 m [] = m -- empty row, do nothing
update1 m (x:xs) =
  case M.lookup x m of
    Nothing -> M.insert x [] m
    Just route
      | null xs -> ? -- what then?
      | otherwise -> M.insert x (head xs:route) m



------------------------------

Message: 7
Date: Wed, 08 Jun 2011 09:34:35 +1000
From: Arlen Christian Mart Cuss <[email protected]>
Subject: Re: [Haskell-beginners] Function definition order and
        performance
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <1307489675.13690.3.camel@azayaka>
Content-Type: text/plain; charset="UTF-8"

> It's z-encoding, 
> http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/SymbolNames
> 
> Kind of irritating when you come across a z-encoded name containing a z 
> where you don't expect z-encoding.

I'm curious as to what you mean by "where you don't expect z-encoding."
The assembly symbols would seem to 'qualify,' or do they turn up
elsewhere as well?




------------------------------

Message: 8
Date: Wed, 8 Jun 2011 02:06:51 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Function definition order and
        performance
To: Arlen Christian Mart Cuss <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="us-ascii"

On Wednesday 08 June 2011, 01:34:35, Arlen Christian Mart Cuss wrote:
> > It's z-encoding,
> > http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/SymbolNam
> > es
> > 
> > Kind of irritating when you come across a z-encoded name containing a
> > z where you don't expect z-encoding.
> 
> I'm curious as to what you mean by "where you don't expect z-encoding."
> The assembly symbols would seem to 'qualify,' or do they turn up
> elsewhere as well?

Well, you'd expect it in the generated assembly, so you're prepared.
I didn't expect z-encoded names in source files (in comments, of course).
compiler/CgPrimOp.hs has a few pretty ones, e.g.

--  #define unsafeFreezzeByteArrayzh(r,a)       r=(a)
emitPrimOp [res] UnsafeFreezeByteArrayOp [arg] _
   = stmtC (CmmAssign (CmmLocal res) arg)


--  #define sizzeofByteArrayzh(r,a) \
--     r = ((StgArrWords *)(a))->bytes
emitPrimOp [res] SizeofByteArrayOp [arg] _
   = stmtC $
        CmmAssign (CmmLocal res) (cmmLoadIndexW arg fixedHdrSize bWord)

so that caught me off guard.

I particularly like sizzeof :D



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 36, Issue 21
*****************************************

Reply via email to