[Haskell-cafe] need help with syntax...

wren ng thornton wren at freegeek.org
Tue Dec 7 08:32:18 CET 2010


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



More information about the Haskell-Cafe mailing list