This is an advanced topic to the post haskell - syntax in functions , where we wil dicuss the the case expressions.
By the name, you might have figured out that the case expression is, well, expression, if it is an expression, then you can embedded the expression anywhere an expressoin is expected.
an example of the case expression is as such .
describeList :: [a] -> String describeList xs = "The list is " ++ case xs of [] -> "empty." [x] -> "a singleton list." xs -> "a longer list."
so, so with the case expression, Not only can we evaluate expressions based on the possible cases of the value of a variable, we can also do pattern matching.
the following will be dicsussed.
- case expression in general
- case expression is an expression
- patterns aligned to the same columnm with regards to case expressions
- pattern matching in function definition is syntactic sugar for case expression.
-- let_in.hs -- discuss the case expression in general -- have I told you that the pattern-matching is syntactic sugar for case expression? head' :: [a] -> a head' [] = error "No head for empty list!" head' (x:_) = x -- rewrite with the case expression head'' :: [a] -> a head'' xs = case xs of [] -> error "No head for empty list!" (x: _) -> x -- case expression of pattern -> result -- pattern -> result -- pattern -> result -- ... -- case expression can be widely used. -- pattern-matching on functino parameter only when you define functions -- case exprssion can be used anywhere describeList :: [a] -> String describeList xs = "The list is " ++ case xs of [] -> "empty." [x] -> "a singleton list." xs -> "a longer list." -- above can have "pattern-maching" in the middle of an expression -- an equivalent one is like this: describeList' :: [a] -> String describeList' xs = "The list is " ++ what xs where what [] = "empty." what [x] = "a singleton list." what xs = "a longer list."
相关推荐
Programming-in-Haskell-2nd-Edition.pdf
Atom-haskell-ghc-mod.zip,haskell-ghc-mod atom packagehaskell ghc mod atom包,atom是一个用web技术构建的开源文本编辑器。
haskell-mode emacs haskell-mode emacs
Atom-ide-haskell-hoogle.zip,在光标下显示符号的滚动信息艾德·哈斯克尔·胡格尔,atom是一个用web技术构建的开源文本编辑器。
Haskell-Data-Analysis-Cookbook, Haskell数据分析 cookbook的附带源代码 Haskell-Data-Analysis-Cookbook这是 Haskell数据分析 cookbook的附带源代码。最新的源代码可以在GitHub上获得: ...
从1.0.0开始,haskell-ghc-mod提供haskell-completion-backend服务。 注意:在1.0.0之前,提供了ide-backend服务。 它已被废弃以支持ide-haskell的UPI。 您可以在找到描述 执照 版权所有:copyright:2015 Atom-...
安装过程中应在路径上放置一个名为haskell-in-haskell的可执行文件。 否则,您可以使用cabal run haskell-in-haskell --直接运行项目,然后输入要传递的参数。 编译中 要编译Haskell文件,只需运行: haskell-in-...
haskell-ghc-mod原子包 该软件包主要用作后端。 Haskell ghc-mod打开通往ghc-modi的管道,并查询类型,信息并检查错误。 安装与配置 请参考官方文档站点 服务中心API 从1.0.0版本开始,haskell-ghc-mod提供...
Get Programming with HASKELL-2018-英文版
用于 haskell-relational-record 的 MySQL 驱动程序 这个项目被合并到 。 准备 $ git clone git@github.com:khibino/haskell-relational-record.git $ git clone git@github.com:bos/hdbc-mysql.git $ git clone ...
演示医疗用例的参考DAML应用程序 -Haskell-TypeScript-下载
Progrtamming in Haskell 2nd edition ppt仅供学习,禁止用于商业行为。Progrtamming in Haskell 2nd edition ppt仅供学习,禁止用于商业行为。Progrtamming in Haskell 2nd edition ppt仅供学习,禁止用于商业行为...
haskell-chart, haskell的2D 图表库 图 haskell的2D 图表库进一步的信息可以在关联的 wiki中找到。
Server Metaprogramming Ruby-Pyton-Groovy-Haskell-Erlang.pdf
A History of Haskell - Being Lazy With Class
haskell-brainfuck 解释 haskel-brainfuck 作为库分发,但它也包含一个可执行文件来运行 Brainfuck 程序。 你可以在找到 haskell-brainfuck用法图书馆 import HaskBF.Evalimport qualified Data.ByteString.Lazy as ...
Atom-ide-haskell-cabal.zip,Cabal backend provider for ide-haskellIDE Haskell Cabal套餐,atom是一个用web技术构建的开源文本编辑器。
haskell-lsp-client 该软件包适用于希望使其文本编辑器与兼容的文本编辑器的开发人员。 我已经开发了此软件包,并计划将其集成到。 示例客户端 该存储库中包含一个示例客户端。 此示例客户端仅运行并打开在命令行...
Atom-atom-haskell-scry.zip,De-emphasize qualified Haskell identifiers.SCRY,atom是一个用web技术构建的开源文本编辑器。
Atom-atom-haskell-pointfree.zip,atom包:将选择转换为无点或有点表示Haskell无点包,atom是一个用web技术构建的开源文本编辑器。