On 12/6/10 7:26 PM, Daryoush Mehrtash wrote:
I am having hard time understanding the following code.  The code is from
Applicative Parser library:
http://hackage.haskell.org/packages/archive/uu-parsinglib/2.5.5.2/doc/html/src/Text-ParserCombinators-UU-BasicInstances.html

  instance (Show a,  loc `IsLocationUpdatedBy` a) =>  Provides  (Str  a
loc)  (a ->  Bool, String, a)  a where
     splitState (p, msg, a) k (Str  tts   msgs pos  del_ok)
           = let ins exp = ...1
                 del exp = ...2
             in case tts of
                (t:ts)  ->   if p t
                            then  ...3
                            else  Fail [msg] (*ins:* if *del_ok* then
*[del*] else [])
                []      ->   Fail [msg] [*ins*]


Specifically I am having hard time understanding how the "ins exp" and "del
exp" in the "let" is related to "ins:"  "del_ok", [del], [ins].
I don't understand how given the "let" expression the following expressions
are expanded

The let expressions are binding functions so ins names (\exp -> ...1) and del names (\exp -> ...2). Thus, when del_ok is true we get,

    Fail [msg] (ins : if del_ok then [del] else [])
    ==
    Fail [msg] (ins : if del_ok then del : [] else [])
    ==
    Fail [msg] (ins : del : [])
    ==
    Fail [msg] ((\exp -> ...1) : (\exp -> ...2) : [])

and when del_ok is false we get

    Fail [msg] ((\exp -> ...1) : [])

--
Live well,
~wren

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to