Understanding Polytypes in Hindley

I'm reading the Wikipedia article on Hindley–Milner Type Inference trying to make some sense out of it. So far this is what I've understood: Types are classified as either monotypes or polytypes. Monotypes are further classified as either type constants (like int or string ) or type variables (like α and β ). Type constants can either be concrete types (like int and string ) or typ

了解Hindley的多型体

我正在阅读关于Hindley-Milner Type推理的维基百科文章,试图从中得出一些意见。 到目前为止,这是我所理解的: 类型被分类为单形或多形。 Monotypes进一步分为类型常量(如int或string )或类型变量(如α和β )。 类型常量可以是具体类型(如int和string )或类型构造函数(如Map和Set )。 类型变量(如α和β )表现为具体类型的占位符(如int和string )。 现在我在理解多类型时遇到了一些困难,但是在了解一下Hask

How are all graphic and web libraries implemented in Haskell?

I only begin to learn Haskell. I've read that it is a pure functional language and everything in it is immutable. So things like input output, writing and reading databases cause mutability of the state. I know there is a thing in Haskell called monads which allow to use imperative features in Haskell like IO Monad . But I'm interesting is everything imperative in Haskell is implement

Haskell中的所有图形和网络库如何实现?

我只开始学习Haskell。 我读过它是一种纯粹的函数式语言,其中的一切都是不变的。 因此,诸如输入输出,写入和读取数据库等事情会导致状态的可变性。 我知道Haskell中有一个叫做monad的东西,它允许像IO Monad一样使用Haskell中的命令式功能。 但我很感兴趣的是Haskell中的一切都是在单子的帮助下实现的? 在HackageDB上,有很多包可以处理3D图形,数据库,解析HTML,编写Web服务器等等。 这一切背后的总体思路是什么?

What are some good intermediate problems and projects for learning Haskell?

I just recently started diving into Real World Haskell and the book provides some good practice exercises. However, I'd like some suggestions for specific problems people have solved or projects they've completed that have really helped them to better understand the language and its capabilities. What sort of things can I throw myself at that are really going to challenge me? I have

Haskell有什么好的中级问题和项目?

我刚刚开始潜入真实世界Haskell,本书提供了一些良好的练习练习。 但是,我希望针对人们已经解决的具体问题或已完成的项目提出一些建议,这些建议确实帮助他们更好地理解语言及其功能。 我可以把自己扔在什么样的事情上真的会挑战我? 我对语言有适度的理解,以前没有其他功能语言的经验; 哈斯克尔是我第一次跳入这个舞台。 我发现欧拉项目有助于学习基本的语言结构,以帮助我获得Haskell的感受。 当然,这并不是用Hask

Beginners Guide to Haskell?

I've been looking for a decent guide to Haskell for some time, but haven't been able to find one that seems interesting enough to read through and/or makes sense. I've had prior exposure to Haskell a few years back, but I can't remember much about it. I remember the "Aha!"-feeling was incredible when I finally got it, and it was actually fun to play with, so I'm l

初学者指南Haskell?

我一直在寻找一个适合Haskell的体面指南,但是一直没有找到一个看起来足够有趣的阅读和/或有意义的指南。 几年前我已经接触过Haskell,但我不记得太多。 我记得“啊哈!” - 当我终于明白了,感觉是不可思议的,玩起来真的很有趣,所以我正在寻找重新发现失去的哈斯克尔艺术。 我熟悉Ruby和它的函数式编程技巧,所以我认为我并不是完全处于黑暗中。 任何链接? 一些好的地方开始是: 对Haskell的简单介绍 在Haskell中

Writing foldl using foldr

In Real World Haskell , Chapter 4. Functional Programming Write foldl with foldr: -- file: ch04/Fold.hs myFoldl :: (a -> b -> a) -> a -> [b] -> a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) The above code confused me a lot, and some guy called dps rewrote it with some meaningful name to make it clearer a bit: myFoldl stepL zeroL xs = (foldr stepR id x

使用foldr书写foldl

在真实世界Haskell中 ,第4章函数式编程 用foldr写下foldl: -- file: ch04/Fold.hs myFoldl :: (a -> b -> a) -> a -> [b] -> a myFoldl f z xs = foldr step id xs z where step x g a = g (f a x) 上面的代码让我很困惑,有些叫做dps的人用一些有意义的名字来重写它,使它更清晰一些: myFoldl stepL zeroL xs = (foldr stepR id xs) zeroL where stepR lastL accR accInitL = accR (stepL accInitL

Memory footprint of Haskell data types

How can I find the actual amount of memory required to store a value of some data type in Haskell (mostly with GHC)? Is it possible to evaluate it at runtime (eg in GHCi) or is it possible to estimate memory requirements of a compound data type from its components? In general, if memory requirements of types a and b are known, what is the memory overhead of algebraic data types such as: data

Haskell数据类型的内存占用

我如何找到在Haskell中存储某种数据类型的值所需的实际内存量(主要是使用GHC)? 是否可以在运行时对其进行评估(例如,在GHCi中)还是可以从其组件评估复合数据类型的内存需求? 通常,如果类型a和b内存需求是已知的,代数数据类型的内存开销是多少,例如: data Uno = Uno a data Due = Due a b 例如,这些值占用内存中有多少个字节? 1 :: Int8 1 :: Integer 2^100 :: Integer x -> x + 1 (1 :: Int8, 2 :: Int8) [1

Can the type checker help me out here? With type families, maybe?

So I'm writing this little soccer game for some time now, and there's one thing that bugs me from the very beginning. The game follows the Yampa Arcade pattern, so there's a sum type for the "objects" in the game: data ObjState = Ball Id Pos Velo | Player Id Team Number Pos Velo | Game Id Score Objects react to messages, so there's another

类型检查器可以帮助我吗? 有类型的家庭,也许?

所以我现在正在写这个小小的足球比赛,有一件事从一开始就让我感到困惑。 游戏遵循Yampa Arcade模式,所以游戏中的“对象”有一个总和类型: data ObjState = Ball Id Pos Velo | Player Id Team Number Pos Velo | Game Id Score 对象对消息作出反应,所以还有另一种总和类型: data Msg = BallMsg BM | PlayerMsg PM | GameMsg GM data BM = Gained | Lost data PM = GoTo Pos

Transformation under Transformers

I'm having a bit of difficulty with monad transformers at the moment. I'm defining a few different non-deterministic relations which make use of transformers. Unfortunately, I'm having trouble understanding how to translate cleanly from one effectful model to another. Suppose these relations are "foo" and "bar". Suppose that "foo" relates As and Bs t

变形金刚之下的变革

目前,我对monad变压器有点困难。 我正在定义一些使用变形金刚的不同的非确定性关系。 不幸的是,我无法理解如何从一个有效的模型转换到另一个有效的模型。 假设这些关系是“foo”和“bar”。 假设“foo”将As和Bs关联到Cs; 假设“bar”将Bs和Cs与Ds相关联。 我们将用“foo”来定义“bar”。 为了使事情更有趣,这些关系的计算将以不同的方式失败。 (因为bar关系依赖于foo关系,所以它的失败情况是一个超集。)因此,我给出了以下

MonadParallel Instance for Rand

I'm currently working with computations in ReaderT r (Rand StdGen) a which I would like to run in parallel. I've come across Monad Parallel which seems like it will do what I want. There is already an instance of MonadParallel for ReaderT but I had to create my own for Rand from monad-random. However, I'm not sure I've done it right. I'm not too familiar with parallel pro

MonadParallel Instance for Rand

我目前正在ReaderT r (Rand StdGen) a ,我希望并行运行它。 我遇到过Monad Parallel,看起来它会做我想要的。 对于ReaderT已经有MonadParallel的实例,但我必须从monad-random为Rand创建我自己的实例。 但是,我不确定我是否做得对。 我并不太熟悉Haskell中的并行编程,但我相信有一种期望,即并行运行计算应该能够提供与正常运行时相同的值。 因为我为Rand的bindM2实例使用split (因此从同一个初始生成器获取一组不同的

Does GHC removes polymorphic indirection when possible?

showInt :: Int -> String showInt x = show x Does the above code calls show passing the Int dictionary or does it calls directly the function declared on Show Int instance? I mean, does GHC removes polymorphic indirection from generated code when possible? Yes. This is the generated core using GHC 7.4.2: Foo.showInt :: GHC.Types.Int -> GHC.Base.String [... attributes omitted ...] Foo.s

GHC在可能的情况下是否消除多态性间接性?

showInt :: Int -> String showInt x = show x 上面的代码调用是否show传递Int字典或直接调用在Show Int实例上声明的函数? 我的意思是,GHC在可能的情况下是否从生成的代码中移除多态性间接? 是。 这是使用GHC 7.4.2生成的核心: Foo.showInt :: GHC.Types.Int -> GHC.Base.String [... attributes omitted ...] Foo.showInt = GHC.Show.$fShowInt_$cshow 正如你所看到的,它只是一个直接引用GHC.Show.$fShowInt_