在do块外,左箭头<-是什么意思? [英] What does left arrow <- mean outside a do block?

查看:89
本文介绍了在do块外,左箭头<-是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我遇到了以下代码,这让我很困扰

  lowerSafeForeignCall dflags块|(entry,middle,CmmForeignCall {..})<-blockSplit块=做-阻止东西-Block不会以安全的外线通话结尾:|否则=返回块 

这段代码来自 https://phabricator.haskell.org/rGHCb0534f78a73f972e279eed4447a5687bd6a8308e在文件editor/cmm/CmmLayoutStack.hs中

第983行

我真的很想知道第二行中的<-是什么.我相信 lowerSafeForeignCall 是一个函数,并且 | 和'否则'表示此函数使用了防护功能.所以

 (entry,middle,CmmForeignCall {..})<-blockSplit块 

必须是布尔类型.但是<-在任何do块之外.我在网上做了一些搜索,但仍然没有关于此用法的任何线索.

这是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.

解决方案

That's a pattern guard:

guard       →   pat <- infixexp      (pattern guard)

[...]

A guard has one of the following forms:

  • pattern guards are of the form p <- 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

这篇关于在do块外,左箭头&lt;-是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆