I'm working on implementing the UCT algorithm in Haskell, which requires a fair amount of data juggling. Without getting into too much detail, it's a simulation algorithm where, at each "step," a leaf node in the search tree is selected based on some statistical properties, a new child node is constructed at that leaf, and the stats corresponding to the new leaf and all of its
我正在Haskell中实现UCT算法,这需要相当数量的数据杂耍。 在没有深入细节的情况下,这是一个模拟算法,在每个“步骤”中,根据某些统计属性选择搜索树中的叶节点,在该叶中构建新的子节点,并根据新叶子及其所有祖先都会更新。 考虑到所有这些杂耍,我并不十分清楚如何让整个搜索树成为一个不错的数据结构。 相反,我一直在玩ST monad,创建由可变STRef组成的结构。 一个人为的例子(与UCT无关): import Control.Monad imp
In Haskell, how to efficiently get the last item(s) of an infinite list concatenated with a finite list? last does not work, it obviously iterates from the head, so the following never finishes: -- let's have a list of all natural numbers, -- with zero appended arr = [1..] ++ [0] -- it was fast! now get the last item, should be easy res = last arr EDIT : I wonder what is the Haskell's int
在Haskell中,如何有效地获取与有限列表连接的无限列表的最后一个项目? last不起作用,它显然是从头开始迭代,所以以下从不完成: -- let's have a list of all natural numbers, -- with zero appended arr = [1..] ++ [0] -- it was fast! now get the last item, should be easy res = last arr 编辑 :我不知道什么是Haskell的[1..] ++ [0]的内部表示,它最初是“完全未评估”? 如果它在内部将其表示为两个(未评估)列
I am learning Haskell from learnyouahaskell.com. I am having trouble understanding type constructors and data constructors. For example, I don't really understand the difference between this: data Car = Car { company :: String , model :: String , year :: Int } deriving (Show) and this: data Car a b c = Car { company :: a
我正在学习learnyouahaskell.com的Haskell。 我无法理解类型构造函数和数据构造函数。 例如,我不太了解这个之间的区别: data Car = Car { company :: String , model :: String , year :: Int } deriving (Show) 和这个: data Car a b c = Car { company :: a , model :: b , year :: c } d
I have seen several sources echo the opinion that "Haskell is gradually becoming a dependently-typed language". The implication seems to be that with more and more language extensions, Haskell is drifting in that general direction, but isn't there yet. There are basically two things I would like to know. The first is, quite simply, what does "being a dependently-typed langu
我看到有几个消息来源反映了“Haskell正逐渐成为一种依赖型语言”的观点。 这意味着,随着越来越多的语言扩展,Haskell正在朝着这个大方向发展,但目前还没有。 基本上有两件事我想知道。 首先,很简单,“作为一种依赖型语言”究竟意味着什么? (希望不要太过于技术性。) 第二个问题是......缺点是什么? 我的意思是,人们知道我们正在走这条路,所以必须有一些优势。 然而,我们还没有到来,所以肯定会有一些不利因素阻
Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard people saying things like "Every programmer should know Haskell", "You aren't a programmer if you don't know haskell" and so on. However, I'm not exactly sure if I should bother trying to get a brief understanding of that language or not. Playing around with interpreter
可能重复: Haskell与现实世界中的程序编程 很少有人听到人们说“每个程序员都应该知道Haskell”,“如果你不知道Haskell,你就不是程序员”等等。 但是,我不确定是否应该试图简单了解该语言。 与口译员一起玩(直观了解基础知识)至少需要几天(如果不是几周),而且我不确定结果是否值得。 一点背景(了解我的知识) 我已经开始使用可编程计算器开始编程(从10到13年前的某个地方),然后移植到基本的程序,然后移植到
i am working on a haskell compiler written in java using JLex and cup .i finished my lexer file and now i am working on my parser.cup file where i should define my terminals , non-terminals and the grammar. i have already finished the terminal and non-terminal part but now i am stuck in the grammar part so can anyone help or redirect me to any link where i can find a grammar for haskell in this
我正在使用JLex和cup编写用java编写的haskell编译器.i完成了我的词法分析器文件,现在我正在处理我的parser.cup文件,在那里我应该定义我的终端,非终端和语法。 我已经完成了终端和非终端部分,但现在我陷入了语法部分,因此任何人都可以帮助或重定向到任何链接,我可以在这种形式中找到haskell的语法: Variable ::= Nonterminal:name Terminal:name {:RESULT = /* code to execute when the rule is matched and the resul
I'm reading Pierce's Types and Programming Languages book and in the chapter about recursive types he mentions that they can be used to encode the dynamic lambda calculus in a typed language. As an exercise, I'm trying to write that encoding in Haskell but I can't get it to pass the typechecker: {-# LANGUAGE RankNTypes, ScopedTypeVariables #-} data D = D (forall x . x -> x )
我正在阅读Pierce的类型和编程语言书籍,在关于递归类型的章节中,他提到可以用类型化语言编码动态lambda演算。 作为练习,我试图在Haskell中编写该编码,但我无法通过类型检查器: {-# LANGUAGE RankNTypes, ScopedTypeVariables #-} data D = D (forall x . x -> x ) lam :: (D -> D) -> D --lam f = D f lam = undefined ap :: D -> D -> D ap (D f) x = f x --Some examples: myConst :: D myConst = la
How do I write a function that returns everything to Integer? ie f True = 1 f False =0 f 1 = 1 f 2.30 = 2 The only functions of type a -> Integer will be constant functions. This is a free theorem guaranteed by the parametricity of the type (modulo some fudging because of some unsound corners of Haskell). Here's an example of such a function: f :: a -> Integer f _ = 1 There
我如何编写一个返回Integer的函数? 即 f True = 1 f False =0 f 1 = 1 f 2.30 = 2 类型a -> Integer的唯一函数将是常量函数。 这是一个由类型的参数性保证的自由定理(由于Haskell的一些不完善的角落,所以模仿一些欺骗)。 这是一个这样的功能的例子: f :: a -> Integer f _ = 1 一般来说,没有办法做到这一点,而且这也不是可取的,但是您提到的以及其他一些案例可以通过丑陋的黑客获得: f :: Enum n =&
This is my first posting on SO, and I'm relatively new to Haskell, so please excuse any missteps or if my code is not idiomatic! Consider the following two intuitive descriptions of: a, f(a), f(f(a))... A. a list containing: a, the application of f to a, the application of f to that , the application of f to that ... B. a list containing, in the ith position, i nested applications of f
这是我第一次在SO上发帖,而且我对Haskell比较陌生,所以请原谅任何错误或者我的代码不习惯! 考虑以下两个直观的描述:a,f(a),f(f(a))... A.一个包含以下内容的列表:a,应用f到a,应用f到那个 ,f应用到那个 ...... B.一个列表,包含在第i个位置,我嵌套f到a的应用程序。 我的问题是,我试图使用Haskell中的iterate函数进行烧毁。我的真实应用程序是一个模拟,但下面的设计示例突出了这个问题。 import Contro
I've only just dipped my toe in the world of Haskell as part of my journey of programming enlightenment (moving on from, procedural to OOP to concurrent to now functional). I've been trying an online Haskell Evaluator. However I'm now stuck on a problem: Create a simple function that gives the total sum of an array of numbers. In a procedural language this for me is easy enoug
作为编程启蒙之旅的一部分(从程序到OOP到并发到现在的功能),我只是将自己的脚趾蘸到了Haskell的世界中。 我一直在尝试一个在线Haskell评估器。 不过,我现在陷入了一个问题: 创建一个简单的函数,给出数组数组的总和。 在程序语言中,这对我来说很简单(使用递归)(c#): private int sum(ArrayList x, int i) { if (!(x.Count < i + 1)) { int t = 0; t = x.Item(i); t = sum(x,