What does left arrow <- mean outside a do block?Haskell: use of unsafePerformIO for global constant bindings
Time at 1G acceleration to travel 100 000 light years
Build a scale without computer
How can I prevent a user from copying files on another hard drive?
How to recover a single blank shot from a film camera
How do I become a better writer when I hate reading?
How to ask if I can mow my neighbor's lawn
Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?
Can you place a web spell on a surface you cannot see?
How can the US president give an order to a civilian?
Is using Legacy mode is a bad thing to do?
Can you create a noise using Minor Illusion/Thaumaturgy on an area you cannot see?
I'm yearning in grey
How is linear momentum conserved in circular motion?
...and then she held the gun
Fantasy game inventory — Ch. 5 Automate the Boring Stuff
Using roof rails to set up hammock
How "fast" do astronomical events occur?
I wish, I yearn, for an answer to this riddle
Simplify, equivalent for (p ∨ ¬q) ∧ (¬p ∨ ¬q)
Digital signature that is only verifiable by one specific person
How to prevent cables getting intertwined
Are there examples of rowers who also fought?
Is it a bad idea to have a pen name with only an initial for a surname?
Why we can't jump without bending our knees?
What does left arrow
Haskell: use of unsafePerformIO for global constant bindings
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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 lowerSafeForeignCall is a function and the | and 'otherwise' indicate this function uses guards. So
(entry, middle, CmmForeignCall .. ) <- blockSplit block
must be of type Bool. But the <- is outside any do block.
I did some search online but still not a single clue about this usage.
haskell ghc guard-clause pattern-guards
add a comment |
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 lowerSafeForeignCall is a function and the | and 'otherwise' indicate this function uses guards. So
(entry, middle, CmmForeignCall .. ) <- blockSplit block
must be of type Bool. But the <- is outside any do block.
I did some search online but still not a single clue about this usage.
haskell ghc guard-clause pattern-guards
3
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02
add a comment |
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 lowerSafeForeignCall is a function and the | and 'otherwise' indicate this function uses guards. So
(entry, middle, CmmForeignCall .. ) <- blockSplit block
must be of type Bool. But the <- is outside any do block.
I did some search online but still not a single clue about this usage.
haskell ghc guard-clause pattern-guards
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 lowerSafeForeignCall is a function and the | and 'otherwise' indicate this function uses guards. So
(entry, middle, CmmForeignCall .. ) <- blockSplit block
must be of type Bool. But the <- is outside any do block.
I did some search online but still not a single clue about this usage.
haskell ghc guard-clause pattern-guards
haskell ghc guard-clause pattern-guards
edited May 31 at 11:06
Will Ness
48.3k470131
48.3k470131
asked May 31 at 10:36
TheodoraTheodora
9416
9416
3
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02
add a comment |
3
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02
3
3
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02
add a comment |
2 Answers
2
active
oldest
votes
That's a pattern guard:
guard → pat
<-infixexp (pattern guard)
[...]
A guard has one of the following forms:
pattern guards are of the formp <- e, where p is a pattern (see Section 3.17) of type t and e is an expression type t. They succeed if the expression e matches the pattern p, and introduce the bindings of the pattern to the environment.
Where normal guards are limited to a boolean check, pattern guards can match against an arbitrary pattern and define local variables. (In your case entry, middle, and the contents of CmmForeignCall will be directly available in the function body.)
You can think of boolean guards as equivalent to pattern guards with a pattern of True:
| expr
works like
| True <- expr
add a comment |
This is a pattern guard [Haskell-wiki]. Since Haskell'10 a guard is a list of qualifiers. A qualifier can be a condition (like in the old guards), and pattern guards.
Haskell will thus (lazily) evaluate the expression on the right side of the arrow <- and aim to match it with the pattern on the left of the arrow. If that succeeds, than the guard (well that part of the guard) is successful. If all the parts of the guard are successful, then the rule "fires".
In this specific case the only part of the pattern that might fail is the fact that the third item of the 3-tuple is not a CmmForeignCall data constructor. Furthermore by using this pattern guard, we can of course use entry, middle in the body of the expression.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56393471%2fwhat-does-left-arrow-mean-outside-a-do-block%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's a pattern guard:
guard → pat
<-infixexp (pattern guard)
[...]
A guard has one of the following forms:
pattern guards are of the formp <- e, where p is a pattern (see Section 3.17) of type t and e is an expression type t. They succeed if the expression e matches the pattern p, and introduce the bindings of the pattern to the environment.
Where normal guards are limited to a boolean check, pattern guards can match against an arbitrary pattern and define local variables. (In your case entry, middle, and the contents of CmmForeignCall will be directly available in the function body.)
You can think of boolean guards as equivalent to pattern guards with a pattern of True:
| expr
works like
| True <- expr
add a comment |
That's a pattern guard:
guard → pat
<-infixexp (pattern guard)
[...]
A guard has one of the following forms:
pattern guards are of the formp <- e, where p is a pattern (see Section 3.17) of type t and e is an expression type t. They succeed if the expression e matches the pattern p, and introduce the bindings of the pattern to the environment.
Where normal guards are limited to a boolean check, pattern guards can match against an arbitrary pattern and define local variables. (In your case entry, middle, and the contents of CmmForeignCall will be directly available in the function body.)
You can think of boolean guards as equivalent to pattern guards with a pattern of True:
| expr
works like
| True <- expr
add a comment |
That's a pattern guard:
guard → pat
<-infixexp (pattern guard)
[...]
A guard has one of the following forms:
pattern guards are of the formp <- e, where p is a pattern (see Section 3.17) of type t and e is an expression type t. They succeed if the expression e matches the pattern p, and introduce the bindings of the pattern to the environment.
Where normal guards are limited to a boolean check, pattern guards can match against an arbitrary pattern and define local variables. (In your case entry, middle, and the contents of CmmForeignCall will be directly available in the function body.)
You can think of boolean guards as equivalent to pattern guards with a pattern of True:
| expr
works like
| True <- expr
That's a pattern guard:
guard → pat
<-infixexp (pattern guard)
[...]
A guard has one of the following forms:
pattern guards are of the formp <- e, where p is a pattern (see Section 3.17) of type t and e is an expression type t. They succeed if the expression e matches the pattern p, and introduce the bindings of the pattern to the environment.
Where normal guards are limited to a boolean check, pattern guards can match against an arbitrary pattern and define local variables. (In your case entry, middle, and the contents of CmmForeignCall will be directly available in the function body.)
You can think of boolean guards as equivalent to pattern guards with a pattern of True:
| expr
works like
| True <- expr
answered May 31 at 10:41
melpomenemelpomene
67.8k55196
67.8k55196
add a comment |
add a comment |
This is a pattern guard [Haskell-wiki]. Since Haskell'10 a guard is a list of qualifiers. A qualifier can be a condition (like in the old guards), and pattern guards.
Haskell will thus (lazily) evaluate the expression on the right side of the arrow <- and aim to match it with the pattern on the left of the arrow. If that succeeds, than the guard (well that part of the guard) is successful. If all the parts of the guard are successful, then the rule "fires".
In this specific case the only part of the pattern that might fail is the fact that the third item of the 3-tuple is not a CmmForeignCall data constructor. Furthermore by using this pattern guard, we can of course use entry, middle in the body of the expression.
add a comment |
This is a pattern guard [Haskell-wiki]. Since Haskell'10 a guard is a list of qualifiers. A qualifier can be a condition (like in the old guards), and pattern guards.
Haskell will thus (lazily) evaluate the expression on the right side of the arrow <- and aim to match it with the pattern on the left of the arrow. If that succeeds, than the guard (well that part of the guard) is successful. If all the parts of the guard are successful, then the rule "fires".
In this specific case the only part of the pattern that might fail is the fact that the third item of the 3-tuple is not a CmmForeignCall data constructor. Furthermore by using this pattern guard, we can of course use entry, middle in the body of the expression.
add a comment |
This is a pattern guard [Haskell-wiki]. Since Haskell'10 a guard is a list of qualifiers. A qualifier can be a condition (like in the old guards), and pattern guards.
Haskell will thus (lazily) evaluate the expression on the right side of the arrow <- and aim to match it with the pattern on the left of the arrow. If that succeeds, than the guard (well that part of the guard) is successful. If all the parts of the guard are successful, then the rule "fires".
In this specific case the only part of the pattern that might fail is the fact that the third item of the 3-tuple is not a CmmForeignCall data constructor. Furthermore by using this pattern guard, we can of course use entry, middle in the body of the expression.
This is a pattern guard [Haskell-wiki]. Since Haskell'10 a guard is a list of qualifiers. A qualifier can be a condition (like in the old guards), and pattern guards.
Haskell will thus (lazily) evaluate the expression on the right side of the arrow <- and aim to match it with the pattern on the left of the arrow. If that succeeds, than the guard (well that part of the guard) is successful. If all the parts of the guard are successful, then the rule "fires".
In this specific case the only part of the pattern that might fail is the fact that the third item of the 3-tuple is not a CmmForeignCall data constructor. Furthermore by using this pattern guard, we can of course use entry, middle in the body of the expression.
answered May 31 at 10:40
Willem Van OnsemWillem Van Onsem
163k17165254
163k17165254
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56393471%2fwhat-does-left-arrow-mean-outside-a-do-block%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
wiki.haskell.org/Keywords#.3C-
– Will Ness
May 31 at 11:02