haskell

适于初学者的基于终端的文本编辑器 GNU Nano 5.0 版发布

扶醉桌前 提交于 2020-08-09 19:49:27
开源文本编辑器 GNU nano 已经达到了 5.0 版本的里程碑。看看这个新版本带来了哪些功能。 Linux 上有很多 基于终端的文本编辑器 。像 Emacs 和 Vim 这样的编辑器需要经历陡峭的学习曲线和掌握一堆不寻常的键盘快捷键,但公认 GNU nano 更容易使用。 也许这就是为什么 Nano 是 Ubuntu 和许多其他发行版中默认的基于终端的文本编辑器的原因,而即将发布的 Fedora 33 版本 也将把 Nano 设置为终端的默认文本编辑器。 GNU nano 5.0 的新功能 在 GNU nano 5.0 的 变更日志 中提到的一些主要亮点是: -indicator 选项将在屏幕右侧显示一种滚动条,以指示视口在缓冲区中的位置和覆盖范围。 可以用 Alt+Insert 键标记行,你可以用 Alt+Page 和 Alt+PageDown 键跳转到这些标记的行。 执行命令提示符现在可以直接从主菜单中访问。 在支持至少 256 种颜色的终端上,有新的颜色可用。 新的 -bookstyle 模式,任何以空格开头的行都会被认为是一个段落的开始。 用 ^L 刷新屏幕现在在每个菜单中都可以使用。它还会将行与光标居中。 可绑定函数 curpos 已经改名为 location ,长选项 -tempfile 已经改名为 -saveonexit ,短选项 -S 现在是 -softwrap

Window下 分布式框架 thrift的安装

痞子三分冷 提交于 2020-08-09 11:00:28
一、Thrift介绍 Thrift最初由Facebook开发,后来提交给了Apache基金会将Thrift作为一个开源项目。facebook开发使用为了解决系统中各个系统间大数据量的传输通信以及系统之间语言环境不同需要夸平台特性,支持C++,Java,Python,PHP, Ruby,Erlang,Perl, Haskell,C#,JavaScript,Node.js,Smalltalk and OCaml都支持。Thrift是一个典型的CS结构,客户端和服务端使用不同的语言开发。既然客户端和服务端使用不同的语言开发,那么一定要有一种中间语言来关联客户端和服务端语言,这种语言就是IDL(Interface Description Language) 二、Window下Thrift环境安装 1、下载thrift,版本为0.13.0 http://archive.apache.org/dist/thrift/0.13.0/ 在D盘新建一个文件夹thrift,然后将thrift-0.13.0.exe重命名为thrift.exe,在D:\thrift文件夹下 2、修改环境变量 系统变量Path中增加D:\thrift 3、在命令行中查看thrift的版本 thrift -version 来源: oschina 链接: https://my.oschina.net/u/4344048

与Project Euler的速度比较:C vs Python vs Erlang vs Haskell

喜夏-厌秋 提交于 2020-08-09 04:12:02
问题: I have taken Problem #12 from Project Euler as a programming exercise and to compare my (surely not optimal) implementations in C, Python, Erlang and Haskell. 我将 Project Euler 中的 问题#12 作为编程练习并比较了我在C,Python,Erlang和Haskell中的(当然不是最优的)实现。 In order to get some higher execution times, I search for the first triangle number with more than 1000 divisors instead of 500 as stated in the original problem. 为了获得更高的执行时间,我搜索第一个三角形数字,其中有超过1000个除数而不是原始问题中所述的500。 The result is the following: 结果如下: C: C: lorenzo@enzo:~/erlang$ gcc -lm -o euler12.bin euler12.c lorenzo@enzo:~/erlang$ time ./euler12.bin

Efficient way to “keep turning the crank” on a stateful computation

依然范特西╮ 提交于 2020-08-08 06:12:26
问题 I have a stateful process that is modelled as an i -> RWS r w s a . I want to feed it an input cmds :: [i] ; currently I do that wholesale: let play = runGame theGame . go where go [] = finished go ((v, n):cmds) = do end1 <- stepWorld end2 <- ite (SBV.isJust end1) (return end1) $ stepPlayer (v, n) ite (SBV.isJust end2) (return end2) $ go cmds I can try searching for an input of a predetermined size like this: result <- satWith z3{ verbose = True } $ do cmds <- mapM sCmd [1..inputLength]

Yesod 1.2 CSRF protection

痞子三分冷 提交于 2020-08-07 10:31:53
问题 I'm confused about Yesod's CSRF protection, and how Yesod's forms work in general. It's my understanding that Yesod's form system uses a "token" which is passed into the HTML realization of the form as a hidden field. When the form is processed, the token is compared to one stored (or at least recreated) on the server. I'd like to track that down, because the CSRF protection is being triggered spuriously in my development environment, and I'd like to change my environment so the forms work

Can this function be written in point-free style? If not, why?

Deadly 提交于 2020-08-03 15:20:33
问题 One related question is this, but some of the answer say that almost anything can be made point free, so what is wrong with this function? \[x] -> x http://pointfree.io/ doesn't seem to be able to write it in point-free style. Does this mean that it cannot be written that way? If so, what is the theoretical reason for it? I can only observe that the function above is a "crippled" version of head (or last , fwiw) which can only operate on singleton lists. Indeed, applied on non singleton lists

fix vs. ArrowLoop

我怕爱的太早我们不能终老 提交于 2020-08-02 07:16:52
问题 Description of loop from Control.Arrow : The loop operator expresses computations in which an output value is fed back as input, although the computation occurs only once. It underlies the rec value recursion construct in arrow notation. Its source code, and its instantiation for (->) : class Arrow a => ArrowLoop a where loop :: a (b,d) (c,d) -> a b c instance ArrowLoop (->) where loop f b = let (c,d) = f (b,d) in c This immediately reminds me of fix , the fixpoint combinator: fix :: (a -> a)

函数柯里化详解

╄→尐↘猪︶ㄣ 提交于 2020-07-27 21:52:13
函数柯里化详解 在计算机科学中,柯里化(Currying)是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术。这个技术由 Christopher Strachey 以逻辑学家 Haskell Curry 命名的,尽管它是 Moses Schnfinkel 和 Gottlob Frege 发明的。 经典面试题: // 实现一个add方法,使计算结果能够满足如下预期: add(1)(2)(3) = 6; add(1, 2, 3)(4) = 10; add(1)(2)(3)(4)(5) = 15; function add() { // 第一次执行时,定义一个数组专门用来存储所有的参数 var _args = Array.prototype.slice.call(arguments); // 在内部声明一个函数,利用闭包的特性保存_args并收集所有的参数值 var _adder = function() { _args.push(...arguments); return _adder; }; // 利用toString隐式转换的特性,当最后执行时隐式转换,并计算最终的值返回 _adder.toString = function () { return _args.reduce(function (a, b) {

07-09 面向过程与函数式

时光怂恿深爱的人放手 提交于 2020-07-27 14:48:21
[TOC] 一 编程范式 ​ 很多初学者在了解了一门编程语言的基本语法和使用之后,面对一个’开发需求‘时仍然会觉得无从下手、没有思路/套路,本节主题“编程范式”正是为了解决该问题,那到底什么是编程范式呢? 编程范式指的就是编程的套路,打个比方,如果把编程的过程比喻为练习武功,那编程范式指的就是武林中的各种流派,而在编程的世界里常见的流派有:面向过程、函数式、面向对象等,本节我们主要介绍前两者。 ​ 在正式介绍前,我们需要强调:“功夫的流派没有高低之分,只有习武的人才有高低之分“,在编程世界里更是这样,各种编程范式在不同的场景下都各有优劣,谁好谁坏不能一概而论,下面就让我们来一一解读它们。 插图:恶搞图62 二 面向过程 ​ ”面向过程“核心是“过程”二字,“过程”指的是解决问题的步骤,即先干什么再干什么......,基于面向过程开发程序就好比在设计一条流水线,是一种机械式的思维方式,这正好契合计算机的运行原理:任何程序的执行最终都需要转换成cpu的指令流水按过程调度执行,即无论采用什么语言、无论依据何种编程范式设计出的程序,最终的执行都是过程式的。 插图:恶搞图63 ​ 详细的,若程序一开始是要着手解决一个大的问题,按照过程式的思路就是把这个大的问题分解成很多个小问题或子过程去实现,然后依次调用即可,这极大地降低了程序的复杂度。举例如下: ​ 写一个数据远程备份程序,分三步

Memoization in Haskell?

有些话、适合烂在心里 提交于 2020-07-24 08:47:25
问题 Any pointers on how to solve efficiently the following function in Haskell, for large numbers (n > 108) f(n) = max(n, f(n/2) + f(n/3) + f(n/4)) I've seen examples of memoization in Haskell to solve fibonacci numbers, which involved computing (lazily) all the fibonacci numbers up to the required n. But in this case, for a given n, we only need to compute very few intermediate results. Thanks 回答1: We can do this very efficiently by making a structure that we can index in sub-linear time. But