haskell

Haskell pattern matching char in a string

拈花ヽ惹草 提交于 2020-11-28 08:26:15
问题 I have a question on pattern matching: Is it possible to somehow match a (string ++ [char] ++ anotherstring)? I have tried something like: f (s++";"++r) = s++r (the rhs is trivial, but its just for testing ;)) But this results in a parse error. 回答1: No, it's not possible. Pattern matching deconstructs values according to the constructors they were built with, so you can only use constructor applications in pattern matching to describe which values match the pattern and which don't. For

Haskell pattern matching char in a string

我的梦境 提交于 2020-11-28 08:23:43
问题 I have a question on pattern matching: Is it possible to somehow match a (string ++ [char] ++ anotherstring)? I have tried something like: f (s++";"++r) = s++r (the rhs is trivial, but its just for testing ;)) But this results in a parse error. 回答1: No, it's not possible. Pattern matching deconstructs values according to the constructors they were built with, so you can only use constructor applications in pattern matching to describe which values match the pattern and which don't. For

Can anybody explain GHC's definition of IO?

情到浓时终转凉″ 提交于 2020-11-28 07:58:33
问题 The title is pretty self-descriptive, but there's one part that caught my attention: newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) Stripping the newtype , we get: State# RealWorld -> (# State# RealWorld, a #) I don't know what State# stands for. Can we replace it with State like this: State RealWorld -> (State RealWorld, a) And can that be expressed as this, then? State (State RealWorld) a This particular construct caught my attention. I know that conceptually, type IO a =

Can anybody explain GHC's definition of IO?

∥☆過路亽.° 提交于 2020-11-28 07:56:59
问题 The title is pretty self-descriptive, but there's one part that caught my attention: newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #)) Stripping the newtype , we get: State# RealWorld -> (# State# RealWorld, a #) I don't know what State# stands for. Can we replace it with State like this: State RealWorld -> (State RealWorld, a) And can that be expressed as this, then? State (State RealWorld) a This particular construct caught my attention. I know that conceptually, type IO a =

What does left arrow <- mean outside a do block?

*爱你&永不变心* 提交于 2020-11-27 05:02:34
问题 I came across with the following code recently and it bothers me a lot lowerSafeForeignCall dflags block | (entry, middle, CmmForeignCall { .. }) <- blockSplit block = do -- do block stuffs -- Block doesn't end in a safe foreign call: | otherwise = return block This piece of code is from https://phabricator.haskell.org/rGHCb0534f78a73f972e279eed4447a5687bd6a8308e in file compiler/cmm/CmmLayoutStack.hs line 983 I really would like to konw what is this <- in the second line. I believe

What does left arrow <- mean outside a do block?

被刻印的时光 ゝ 提交于 2020-11-27 05:01:45
问题 I came across with the following code recently and it bothers me a lot lowerSafeForeignCall dflags block | (entry, middle, CmmForeignCall { .. }) <- blockSplit block = do -- do block stuffs -- Block doesn't end in a safe foreign call: | otherwise = return block This piece of code is from https://phabricator.haskell.org/rGHCb0534f78a73f972e279eed4447a5687bd6a8308e in file compiler/cmm/CmmLayoutStack.hs line 983 I really would like to konw what is this <- in the second line. I believe

C++模版编程实现Haskell的函数模式匹配特性[图]

老子叫甜甜 提交于 2020-11-25 07:55:21
C++模版编程实现Haskell的函数模式匹配特性[图]: 大神 Bartosz Milewski 在2009年写了一篇文章《What Does Haskell Have to Do with C++?》,使用C++实现Haskell函数式编程语言的一些特性。【传送门在文末】 其中有这样一段例子: // code 1 1.template<int n>class fact { 2.public: 3. staticconstint value = n * fact<n -1>::value; 4.}; 5. 6.template<>class fact<0>{// specialization for n = 0 7.public: 8. staticconstint value =1; 9.}; 注:原文中使用的是struct关键字,这里改为class并加上了public 我猜,你没看懂。没关系,我们先跳过上面这一段有着【令人恐怖的语法】的C++模版代码。 上面的例子想干嘛呢?其实它只是想计算n的阶乘。 如果你在C语言里面学过递归,应该知道下面这段计算阶乘的递归函数 // code 2 int fact(int n){ if(0== n ) return1; //0阶问题答案。0! 等于1 else return( n * fact( n -1)); //问题降阶:n阶->n

Littlest JupyterHub| 06 使用conda,pip或apt方式安装依赖库

淺唱寂寞╮ 提交于 2020-11-19 10:47:23
在TLJH中,所有的用户使用的是同一个conda环境,用户可以调用环境中的所有软件包,管理员可以通过多种方式为用户安装所需要的软件环境。 通过pip安装依赖包 pip工具用于从Python Packaging Index(PyPI)中下载安装依赖,PyPI中有超过145000个软件包。 1、使用管理员权限登录JupyterHub并打开一个命令行窗口 2、输入安装命令 sudo -E pip install <packages-name> 根据需要将命令中尖括号部分进行替换,以安装numpy为例: 通过conda安装依赖包 conda可以安装来自其他语言中的软件包,如node,R等,特别是当依赖包需要链接到C/Fortran代码时,推荐使用conda而不是pip安装 1、使用管理员权限登录JupyterHub并打开一个命令行窗口 2、输入安装命令 sudo -E conda install -c conda-forge <package-name> 根据需要将命令中尖括号部分进行替换,以安装gdal为例: 通过apt安装依赖包 apt是 Ubuntu Linux 发行版的官方软件包管理器,它可以安装实用程序(如 vim、 sl、 htop 等)、服务器应用(postgres、 mysql、 nginx 等)、比 conda 支持更多的语言(haskell、 prolog、