pattern-guards

What does left arrow <- mean outside a do block?

*爱你&永不变心* 提交于 2020-11-27 05:02:34
问题 I came across with the following code recently and it bothers me a lot lowerSafeForeignCall dflags block | (entry, middle, CmmForeignCall { .. }) <- blockSplit block = do -- do block stuffs -- Block doesn't end in a safe foreign call: | otherwise = return block This piece of code is from https://phabricator.haskell.org/rGHCb0534f78a73f972e279eed4447a5687bd6a8308e in file compiler/cmm/CmmLayoutStack.hs line 983 I really would like to konw what is this <- in the second line. I believe

What does left arrow <- mean outside a do block?

被刻印的时光 ゝ 提交于 2020-11-27 05:01:45
问题 I came across with the following code recently and it bothers me a lot lowerSafeForeignCall dflags block | (entry, middle, CmmForeignCall { .. }) <- blockSplit block = do -- do block stuffs -- Block doesn't end in a safe foreign call: | otherwise = return block This piece of code is from https://phabricator.haskell.org/rGHCb0534f78a73f972e279eed4447a5687bd6a8308e in file compiler/cmm/CmmLayoutStack.hs line 983 I really would like to konw what is this <- in the second line. I believe

Is there, in Haskell, something similar to sub-guards?

醉酒当歌 提交于 2019-12-17 12:48:12
问题 I'm writing a program on the classification of musical intervals. The conceptual structure is quite complicated and I would represent it as clearly as possible. The first few lines of code are a small extract that works properly. The second are the pseudo-code that would meet my needs of conciseness. interval pt1 pt2 | gd == 0 && sd < (-2) = ("unison",show (abs sd) ++ "d") | gd == 0 && sd == (-2) = ("unison","dd") | gd == 0 && sd == (-1) = ("unison","d") | gd == 0 && sd == 0 = ("unison","P")

Haskell - guard inside case statement

女生的网名这么多〃 提交于 2019-12-03 10:01:48
I am going through Learn you a haskell book, and in Chapter 8 there is a snippet of code which looks like this data LockerState = Taken | Free deriving (Eq, Show) type Code = String type LockerMap = Map.Map Int (LockerState, Code) lookup' :: Int -> LockerMap -> Either String Code lookup' num_ map_ = case (Map.lookup num_ map_) of Nothing -> Left $ "LockerNumber doesn't exist!" Just (state, code) -> if state == Taken then Left $ "LockerNumber already taken!" else Right $ code This works. However, I wanted to convert if/else block to guard statements like this: lookup' :: Int -> LockerMap ->

Reusing patterns in pattern guards or case expressions

。_饼干妹妹 提交于 2019-11-30 03:00:50
问题 My Haskell project includes an expression evaluator, which for the purposes of this question can be simplified to: data Expression a where I :: Int -> Expression Int B :: Bool -> Expression Bool Add :: Expression Int -> Expression Int -> Expression Int Mul :: Expression Int -> Expression Int -> Expression Int Eq :: Expression Int -> Expression Int -> Expression Bool And :: Expression Bool -> Expression Bool -> Expression Bool Or :: Expression Bool -> Expression Bool -> Expression Bool If ::

Is there, in Haskell, something similar to sub-guards?

我的梦境 提交于 2019-11-27 15:05:39
I'm writing a program on the classification of musical intervals. The conceptual structure is quite complicated and I would represent it as clearly as possible. The first few lines of code are a small extract that works properly. The second are the pseudo-code that would meet my needs of conciseness. interval pt1 pt2 | gd == 0 && sd < (-2) = ("unison",show (abs sd) ++ "d") | gd == 0 && sd == (-2) = ("unison","dd") | gd == 0 && sd == (-1) = ("unison","d") | gd == 0 && sd == 0 = ("unison","P") | gd == 0 && sd == 1 = ("unison","A") | gd == 0 && sd == 2 = ("unison","AA") | gd == 0 && sd > 2 = (