haskell - Haskell 中是否有“of”语法?
问题描述
newtype State s a = StateOf (s -> (s, a))
deState :: State s a -> (s -> (s, a))
deState (StateOf stf) = stf
instance Functor (State s) where
-- fmap :: (a -> b) -> State s a -> State s b
fmap f (StateOf stf) = StateOf (\s0 -> case stf s0 of (s1, a) -> (s1, f a))
在最后一行
fmap f (StateOf stf) = StateOf (\s0 -> case stf s0 of (s1, a) -> (s1, f a))
of
语法让我感到困惑。它似乎不是case
语法的一部分。
解决方案
正如@melpomene 评论的那样,“of”是 case 表达式的一部分。请参阅http://learnyouahaskell.com/syntax-in-functions#case-expressions以获取更多参考。case 表达式也包含在一个 lambda 表达式中,我会指向http://learnyouahaskell.com/higher-order-functions#lambdas以供参考。LYAH 过去和现在都是一个很好的来源(至少对我来说)。
推荐阅读
- google-cloud-platform - 如何从 Google 云调度程序定期触发 Google Cloud Build 作业
- php - Doctrine 在水合过程中添加了额外的查询,导致“正常”一对一和自引用关系出现 n+1 问题
- wordpress - 批量删除某些分类的所有术语(Wordpress)
- neural-network - 如何将 MLP 问题转换为 ARFF 文件
- python - 使用 np.loadtxt() 加载数据时出现内存错误
- unity3d - 粒子从一个角度看是黑色的,从另一个角度看是正常的
- google-sheets - 在 Google 电子表格的气泡图中,如何将气泡大小设置为项目的频率?
- c# - WPF 中的嵌入式 Unity 应用程序,鼠标单击后失去焦点(已解决)
- java - 在java中检查密码。它必须包含至少 10 个字母(数字或数字)和至少 2 个数字
- formatting - 对于 C++ 的 Doxygen 块,是否有类似 linter/formatter/正确性检查器的东西?