haskell

How are list comprehensions implemented in Haskell?

爱⌒轻易说出口 提交于 2021-01-27 03:51:38
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

How are list comprehensions implemented in Haskell?

心已入冬 提交于 2021-01-27 03:51:30
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

How are list comprehensions implemented in Haskell?

二次信任 提交于 2021-01-27 03:51:24
问题 Are list comprehensions simply a language feature? What's the easiest way to fake a list comprehension using pure Haskell? Do you have to use a do block/ >>= to do this or could you use some other method for hacking a list comprehension together? Clarification: By "fake" a list comprehension I mean create a function that takes the same input and produces the same input, i.e. a form for the return values, lists to crunch together, and a predicate or multiple predicates. 回答1: Section 3.11 in

In GHCi, why can't I show `pure 1` in REPL?

耗尽温柔 提交于 2021-01-27 03:51:12
问题 I tried to assign a lifted value to a . λ> :m Control.Applicative λ> let a = pure 1 When I evaluated a in REPL, it prints 1 . λ> a 1 Therefore, I thought there may be an implementation of show for a , and tried this: λ> show a But the GHCi throws an error: <interactive>:70:1-4: No instance for (Show (f0 a0)) arising from a use of ‘show’ The type variables ‘f0’, ‘a0’ are ambiguous Note: there are several potential instances: instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- Defined

How can I persist the environment between GHCi reloads?

半腔热情 提交于 2021-01-27 03:48:55
问题 Basically when I :load name.hs the variables and bindings are gone. Is there some option to tell ghci keep it all? 回答1: To load a new module, you can use Prelude> :m + Mymodule But reloading and keeping interactive bindings is not generally possible. Reloading is essentially forgetting all modules and loading them again. The bindings could depend on already loaded modules. The dependency logic dictates that when GHCI forgets a module, it also needs to forget everything that depends on it,

How can I persist the environment between GHCi reloads?

久未见 提交于 2021-01-27 03:44:16
问题 Basically when I :load name.hs the variables and bindings are gone. Is there some option to tell ghci keep it all? 回答1: To load a new module, you can use Prelude> :m + Mymodule But reloading and keeping interactive bindings is not generally possible. Reloading is essentially forgetting all modules and loading them again. The bindings could depend on already loaded modules. The dependency logic dictates that when GHCI forgets a module, it also needs to forget everything that depends on it,

Haskell学习笔记(一) 安装

不想你离开。 提交于 2021-01-27 02:55:48
官网地址:https://www.haskell.org/downloads/ 1.在 官网 下载安装包。这里我直接下载的Haskell Platform安装包。有的教程推荐下载stack再进行后续安装,原因是platform版本之间存在一些不稳定的情况。但是下载platform是一种比较轻松省事的安装方式。(顺便祈祷不要出现不稳定的bug) 2.双击运行安装包,路径最好就不要改了,或者要好记一点。 在安装过程中会出现stack安装的弹窗 3.安装完毕之后,打开命令行输入 cabal user-config init ,会出现默认的放置配置文件的地址,然后到那个文件夹下修改config文件。 检查文件中是否有以下语句   extra-prog-path: 文件安装路径\msys\usr\bin   extra-lib-dirs: 文件安装路径\mingw\lib   extra-include-dirs: 文件安装路径\mingw\include 如果没有,在文件结尾加上。另外,以上三个路径可以存在由逗号隔开的多个地址。保存并关闭config文件。 4.打开开始菜单,可以看到GHCi和WinGHCi。GHCi是Haskell的解释器,使用类似于Python的shell或者MATLAB的命令行,输入算式敲回车就能进行计算。但是如果要进行复杂运算就需要编写程序、编译运行了

Haskell语言学习笔记(76)Data.Tree

血红的双手。 提交于 2021-01-27 02:01:46
Data.Tree data Tree a = Node { rootLabel :: a, subForest :: Forest a } deriving (Eq, Read, Show) type Forest a = [Tree a] Data.Tree 是一种非空(存在根节点),可以有无限分支,每个节点均可有多路分支的Tree类型。 Prelude Data.Tree> :t Node 1 Node 1 :: Num a => Forest a -> Tree a Prelude Data.Tree> a = Node 1 [Node 2 [], Node 3 []] Prelude Data.Tree> a Node {rootLabel = 1, subForest = [Node {rootLabel = 2, subForest = []},Node {rootLabel = 3, subForest = []}]} Prelude Data.Tree> putStr $ drawTree $ fmap show a 1 | +- 2 | `- 3 Prelude Data.Tree> foldTree (\x xs -> sum (x:xs)) a 6 Prelude Data.Tree> foldTree (\x xs -> maximum (x:xs)) a

Haskell的学习笔记

风格不统一 提交于 2021-01-27 00:25:30
欢迎访问个人博客,阅读此文 http://www.yandong.org/archives/228 刚开始学习Haskell,在此做个总结吧,主要整理一下搜集到的资源,并安排下面的学习 介绍 Haskell是一种纯函数式编程语言,它的命名源自美国数学家Haskell Brooks Curry,他在数学逻辑方面上的工作使得函数式编程语言有了广泛的基础。 Haskell语言是1990年在编程语言Miranda的基础上标准化的,并且以λ演算为基础发展而来。这也是为什么Haskell语言以希腊字母“λ”(Lambda)作为自己的标志 Haskell语言的最重要的两个应用是Glasgow Haskell Compiler(GHC)和Hugs(一个Haskell语言的编译器)。 Haskell史话 —读点历史 学习资源 Haskell的中文资料少得可怜,英文倒是很多(我英文很烂那),下面是搜集到的一些中文资料。 Haskell-wiki教程 —-非常易懂,可以先看一会这个 Haskell趣学指南 —-写的不错, Real word Haskell中文翻译 —-进阶读物,不重理论,注重实用 Haskell的安装配置问题 —-一些诶小问题,小概念 TopLanguage上关于Haskell的一些讨论 豆瓣上Haskell小组 学习Haskell的现实意义 —-如果你还在无聊的争论和蛋疼的抉择中