- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在阅读Scrap your type classes 。这为类型类提供了替代方案。然而,我被Paul Chiusano的评论所困扰。其中讨论了恢复 do 表示法 语法。
坦白说,我无法理解
return :: a -> (Monad f -> f a)
(>>=) :: (Monad f -> f a) -> (a -> (Monad f -> f b)) -> (Monad f -> f b)
将有助于恢复do符号
You can implement all the monadic combinators like this, and desugar do notation to them. The do block evaluates to a function that accepts the monad dictionary, so you can even conveniently write code that's polymorphic in the choice of monad, without having to thread the dictionary around manually.
尤其是,它如何适应上面文章中提到的 GADT 风格方法的上下文?
最佳答案
{-# LANGUAGE Rank2Types, RebindableSyntax #-}
import qualified Prelude
import qualified System.IO
import Prelude (String, ($), (++))
import System.IO (IO)
根据加布里埃尔·冈萨雷斯的建议
data MonadI f = MonadI {
_return :: forall a . a -> f a,
_bind :: forall a b . f a -> (a -> f b) -> f b
}
您可以按如下方式实现必要的函数 return
和 (>>=)
,并使用 Paul Chiusano 建议的类型:
return :: a -> (MonadI f -> f a)
return x = \dict -> (_return dict) x
(>>=) :: (MonadI f -> f a) -> (a -> (MonadI f -> f b)) -> (MonadI f -> f b)
ma >>= f = \dict -> (_bind dict) (ma dict) (\x -> f x dict)
这不足以恢复 do 符号,因为您还需要 (>>)
和 ( sadly ) fail
。您可以按如下方式实现它们:
(>>) :: (MonadI f -> f a) -> (MonadI f -> f b) -> (MonadI f -> f b)
ma >> mb = ma >>= (\_ -> mb)
fail :: String -> MonadI f -> f a
fail str = \_ -> Prelude.error str -- Because let's not further entertain that idea.
现在我们拥有编写简单程序所需的工具:
main :: IO ()
main = (\m -> m monad'IO) $ do
putStrLn "What is your name?"
name <- getLine
putStrLn $ "Hello, " ++ name
当然,为此我们必须从 System.IO
借用一些东西:
getLine :: MonadI IO -> IO String
getLine = \_ -> System.IO.getLine
putStrLn :: String -> (MonadI IO -> IO ())
putStrLn str = \_ -> System.IO.putStrLn str
monad'IO :: MonadI IO
monad'IO = MonadI {
_return = (Prelude.return :: a -> IO a),
_bind = ((Prelude.>>=) :: IO a -> (a -> IO b) -> IO b)
}
关于haskell - 恢复 do 表示法语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33422437/
我正在从事一个项目,我必须将 Pocketsphinx 的语音功能集成到一个 Android 应用程序中。事实上,我必须集成 Pocketpshinx 提供的音素识别功能,它应该能够识别法语中的音素,
我想在 javascript/php 中实现法语、俄语等外语的拼写纠正。对于英语拼写检查器,我可以使用编辑距离算法从英语词典中检索单词(词典是使用 Trie 构建的)并返回出现频率最高的单词。我还找到
我有一个 .NET MVC 页面,其中包含每个项目的列表 rel 中的编码描述.我希望能够搜索带有 rel 的所有项目包含我的搜索查询。 其中一个字段的值为 htmlentities rel='D&
我有这种日期格式: Mon, Nov 19, 2018 我希望它采用法语短日期格式(DD/MM/YYY) 但我无法用excel的基本日期格式解决它。 有任何想法吗 ? 最佳答案 您可以使用 MATCH
我有一个 Excel,其中每个月都会创建一个名为 kpi_monthname 的工作表,其中月份名称包含该月的前 3 个字符。就像 5 月一样,它显示为 kpi_mai 或 4 月它显示为 kpi_a
我想知道,如果这样 alph = ['a'..'z'] 返回我 "abcdefghijklmnopqrstuvwxyz" 那我怎样才能返回法语字母呢?我可以通过某种方式传递语言环境吗? 更新:嗯)我知
法语含糊的语言问题。我正在建立一个有 5 种语言的网站。我已经使用 PHP 设置了法语等语言文件 $lang['Description'] = 'Photos'; $lang['cookie']= "
Popup Click me to toggle the popup! A Simple Popup! // When the user clicks on div, open the po
所以我正在为我目前工作的法国客户做一个网站,我正在为网站使用来自 Google Fonts 的名为 Comfortaa 的字体。该网站是法语的,因此使用带有重音符号的字母,例如 é à 和 è 然而,
我在一个网站上实现了一个语言插件,你知道排序点击并将所有内容更改为阿拉伯语、俄语..等(我知道现代浏览器已经为此内置了功能,但我们选择了去这样。) 我一直在徘徊的是,如果我们的正常网站正在运行,我们如
我开发了一个短信发送器应用程序,我想知道用户使用的语言。那么,当用户键入一条消息时,我如何知道他/她使用的语言? 最佳答案 通过使用获取输入类型管理器: InputMethodManager imm
我有如下一段代码 public static void main(String[] args) throws UnsupportedEncodingException { System
我想验证任何给定格式的日期格式。例如。法语:14-déc-2017。在普通英语中,14-Dec-2017 采用 %d-%b-%Y 格式。我想要的是任何语言格式的给定日期都应该得到验证。 在Python
我正在尝试初始化FrenchStemmer: stemmer = nltk.stem.FrenchStemmer('french') 错误是: AttributeError: 'module' obj
这个问题已经有答案了: Microsoft Excel mangles Diacritics in .csv files? (22 个回答) 已关闭 3 年前。 我正在尝试生成不同语言的报告,例如法语
我有一个旧的 SQL4 数据库,我正在尝试将其重新上传到我们在 Phpmyadmin 上新创建的数据库。表中的字符是拉丁文和日文。我尝试更改这些特定列,但结果仍然是我需要以日语显示的列的损坏字符。 这
我有一个日期字符串,我想将其解析为日期时间对象。我有这个: $invoice = '9 février 2017' [datetime]::parseexact($invoice, 'dd MMMM
我只是想知道在网页上处理多种语言的最佳方法是什么?我应该在负载中创建一个事件,将所有控件的标签更改为适当的语言文本,还是有更好的方法?我正在使用.NET框架,谢谢。 最佳答案 对于 ASP.NET,请
我应该如何在一个供全局使用的网站上存储(和展示)多种语言的文本?内容主要是 500 多字文章的形式,尽管我还需要翻译每一页上的小段文字(例如“打印这篇文章”或“返回菜单”)。 我知道有几个 CMS 包
晚上好! 我在瑞典 Mac 上开发了一个英文宏。该宏在法国使用的带有法语 Excel 的 Mac 上运行。所有的子程序都工作得很好……但只有一个。我使用了公式“=VALUTA(123,4567)”[瑞
我是一名优秀的程序员,十分优秀!