首页 \ 问答 \ Smalltalk / Squeak消息处理方法(Smalltalk / Squeak message handling method)

Smalltalk / Squeak消息处理方法(Smalltalk / Squeak message handling method)

一个非常简短的问题 - 如何命名消息处理方法(在消息传递时调用的第一个方法),以及在哪个类中定义它?


A pretty short question - how is the message handling method named (the first method that is called on message passing), and in which class it is defined?


原文:
更新时间:2022-04-26 13:04

最满意答案

要回答这个问题,知道什么是准引用是有帮助的。 从GHC文档中 ,准引号是一个值

data QuasiQuoter = QuasiQuoter { quoteExp  :: String -> Q Exp,
                                 quotePat  :: String -> Q Pat,
                                 quoteType :: String -> Q Type,
                                 quoteDec  :: String -> Q [Dec] }

也就是说,它是从任意String到ExpQPatQTypeQDecQ一个或多个的DecQ ,它们分别是表达式,模式,类型和声明的模板Haskell表示。

当您使用准引号时,GHC将解析器应用于String以创建ExpQ (或其他类型),然后在生成的模板haskell表达式中拼接以生成实际值。

听起来你要做的就是将quasiquote解析和拼接分开,这样你就可以访问TH表达式了。 然后您可以将该表达式导入另一个模块并自己将其拼接在那里。

知道准引物的类型,很明显这是可能的。 通常你使用QQ作为

-- file Expr.hs
eval :: Expr -> Integer
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat =  parseExprPat }

-- file Foo.hs
import Expr
myInt = eval [expr|1 + 2|]

相反,您可以自己提取解析器,获取TH表达式,然后将其拼接:

-- file Foo.hs
import Expr

-- run the QQ parser
myInt_TH :: ExpQ
myInt_TH = quoteExp expr "1 + 2"

-- file Bar.hs
import Foo.hs

-- run the TH splice
myInt = $(myInt_TH)

当然,如果您自己编写所有这些内容,则可以跳过准引号并直接使用解析器和模板Haskell。 这两种方式几乎都是一样的。


To answer this, it's helpful to know what a quasi-quoter is. From the GHC Documentation, a quasi-quoter is a value of

data QuasiQuoter = QuasiQuoter { quoteExp  :: String -> Q Exp,
                                 quotePat  :: String -> Q Pat,
                                 quoteType :: String -> Q Type,
                                 quoteDec  :: String -> Q [Dec] }

That is, it's a parser from an arbitrary String to one or more of ExpQ, PatQ, TypeQ, and DecQ, which are Template Haskell representations of expressions, patterns, types, and declarations respectively.

When you use a quasi-quote, GHC applies the parser to the String to create a ExpQ (or other type), then splices in the resulting template haskell expression to produce an actual value.

It sounds like what you're asking to do is separate the quasiquote parsing and splicing, so that you have access to the TH expression. Then you can import that expression into another module and splice it there yourself.

Knowing the type of a quasi-quoter, it's readily apparent this is possible. Normally you use a QQ as

-- file Expr.hs
eval :: Expr -> Integer
expr = QuasiQuoter { quoteExp = parseExprExp, quotePat =  parseExprPat }

-- file Foo.hs
import Expr
myInt = eval [expr|1 + 2|]

Instead, you can extract the parser yourself, get a TH expression, and splice it later:

-- file Foo.hs
import Expr

-- run the QQ parser
myInt_TH :: ExpQ
myInt_TH = quoteExp expr "1 + 2"

-- file Bar.hs
import Foo.hs

-- run the TH splice
myInt = $(myInt_TH)

Of course if you're writing all this yourself, you can skip the quasi-quotes and use a parser and Template Haskell directly. It's pretty much the same thing either way.

相关问答

更多
  • 原则上, wx-config绝对应该能够在同一个库的多个版本之间进行选择(这大约是其整个逻辑和目的的90%),但是恐怕wx-config逻辑的构建选择和 - --host选项,这将需要选择正确的构建在你的情况。 我不确定自己,因为我实际上从不使用wx-config在多个构建中进行选择,而是根本不安装它们并使用构建目录中的脚本。 即我确定的工作是: $ mkdir -p ~/build/wx/gtk $ cd $_ $ ~/src/wx/configure # of course, you can add o ...
  • 下面是从“学习你一个好主意的Haskell!”的Haskell模块介绍: http://learnyouahaskell.com/modules 我会将这个包称为Haskell软件的最小可交付单元。 对于大多数人来说,“包是Hackage上的东西”就足够了 。 如果你正在发布一个可执行文件,我不会担心你的项目分成多个软件包,直到你开始第二个项目,并且希望从第一个开始重新使用模块。 Here is an introduction Haskell modules from "Learn You a Haskel ...
  • 就关键而言,它仅适用于Places网络服务: https : //developers.google.com/maps/documentation/places/ 您的文档链接指向Places库 - 这是JavaScript API v3的一项服务。 这里不需要一个关键字,但是当您加载Maps JS( https://developers.google.com/maps/documentation/javascript/tutorial#HelloWorld )时,您可以通过添加&key={yourkey} ...
  • -- Filter a list... filter -- ...of nested tuples where the first element of the second element of the tuple... (\(_, (variable1, _)) -> -- ...is not an element of [something1, something2] variable1 `notElem` [something1, something2]) (_, (varible1, _) ...
  • 您可以将其转换为PrintfArg类型,以便以所需的格式打印它,例如 printf "%.3f" (realToFrac delta :: Double) 可以。 You can convert it to a PrintfArg type to print it in the desired format, e.g. printf "%.3f" (realToFrac delta :: Double) does it.
  • 你只需要安装自制软件,如果你在主目录下这样做,你可以不使用root权限。 然后,您可以brew install cabal-install ,它将自动安装cabal和ghc,或者brew install stack以安装堆栈。 You just need to install homebrew, which you can do without root rights if you do so in your home directory. You can then brew install cabal-i ...
  • GetLastError()返回由此线程调用的WinAPI函数设置的最后一个错误代码。 请注意,WinAPI函数在成功时不一定会设置代码: 大多数函数只有在失败时才会调用SetLastError或SetLastErrorEx。 您尚未调用失败的WinAPI函数。 因此,错误代码是不确定的。 它或者是未初始化的(意思是未定义的行为),或者是由未知函数设置的(只是稍微没有意义)。 标准库使用异常来表示错误,而不是Windows API。 “这是行为吗?” 预期这种行为意味着任何值都可以接受,因为该函数没有在正确 ...
  • 除非已经使用GHC -split-objs选项进行编译,否则库模块将作为一个整体进行链接。 但是这会使编译速度变慢,所以它不是默认值。 从GHC文档 : 然而,分别组装所有部分是昂贵的,所以这比编译通常慢。 我们使用这个特性来构建GHC的库(警告:除非你知道你在做什么,否则不要使用它)。 A library module is linked as a whole unless it has been compiled with the GHC -split-objs option. However this ...
  • 您可能正在从最新版本的http-conduit寻找httpSource 。 它的行为与Python的请求非常相似:您可以获得大量的块。 保存到文件 这很简单,只需将源直接重定向到文件接收器即可。 #!/usr/bin/env stack {- stack --install-ghc --resolver nightly-2016-11-26 runghc --package http-conduit -} {-# LANGUAGE OverloadedStrings #-} import Network. ...
  • 要回答这个问题,知道什么是准引用是有帮助的。 从GHC文档中 ,准引号是一个值 data QuasiQuoter = QuasiQuoter { quoteExp :: String -> Q Exp, quotePat :: String -> Q Pat, quoteType :: String -> Q Type, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)