[Haskell-cafe] How to understand `|` in this code snippet ?

zaxis z_axis at 163.com
Sat Feb 27 20:08:18 EST 2010


Then can i change it to :
case timeout of
        Just str -> do
            [(t, _)] <- reads str
            addTimeout t (hPutStrLn stderr "*** TIMEOUT" >> _exit 1)
            return ()
        _ -> return () 

Sincerely!


Brandon S. Allbery KF8NH wrote:
> 
> On Feb 27, 2010, at 04:07 , zaxis wrote:
>>
>> xxxMain = do
>>    timeout <- getEnv "xxx_TIMEOUT"
>>    case timeout of
>>        Just str | [(t, _)] <- reads str -> do
>>            addTimeout t (hPutStrLn stderr "*** TIMEOUT" >> _exit 1)
>>            return ()
>>        _ -> return ()
>> .......
>>
>> What does the `|` mean in "Just str | [(t, _)] <- reads str" ?
>> Is it a logical `or` ?
> 
> It's a guard.  Same as with function definitions (in fact, function  
> definitions of that form are converted to case expressions).
> 
> -- 
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
> 
> 
> 
>  
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 


-----
fac n = let {  f = foldr (*) 1 [1..n] } in f 
-- 
View this message in context: http://old.nabble.com/How-to-understand-%60%7C%60-in-this-code-snippet---tp27726581p27732364.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list