Disclaimer: My ignorance about Haskell is almost perfect. Sorry if this is really basic, but I couldn't find an answer, or even a question like that. Also my English is not that good. As far as I understand, if I have a function in a system that somehow interacts with filesystem this function must use the IO monad, and will have a type like IO () In my (only business oriented) experienc
免责声明:我对Haskell的无知几乎是完美的。 对不起,如果这是非常基本的,但我找不到答案,或者甚至是这样的问题。 我的英语也不太好。 据我所知,如果我在系统中有某种功能与文件系统交互,这个函数必须使用IO monad,并且会有一个类似IO () 在我的(仅面向业务)体验中,系统通常与文件系统进行交互,以便用业务数据读取/写入文件,并进行日志记录。 而在商业应用中,日志无处不在。 所以如果我在Haskell中编写一个
I have aa C++ program calling my Haskell program multiple times. But some data from the first calls needs to be retained for the subsequent calls. I know top-level mutable variables are not supported by default in Haskell but I guess I still need something like that. (Writing my state to a file and reading it back in would work, but I want something more native) On hackage I found libraries
我有一个C ++程序多次调用我的Haskell程序。 但是来自第一次呼叫的一些数据需要保留以用于随后的呼叫。 我知道Haskell默认不支持顶级可变变量,但我想我仍然需要类似的东西。 (把我的状态写入一个文件并重新读取会有用,但我想要更多的本地文件) 在hackage中,我发现像全局变量或安全全局变量这样的库,但它们都显得很老,并且依赖于我已经使用的旧版本的包。 这个问题有没有规范的解决方案? 理想情况下,我想要有顶
There seem to be several priority queue implementations available off-the-shelf for Haskell. For instance, there's: Data.PriorityQueue.FingerTree (in fingertree-0.0.1.0 on hackage) Data.PurePriorityQueue (in pure-priority-queue-0.14 on hackage) both of which appear to be pure priority queue data structures. The former is based on finger trees, a data structure with which I'm unfam
Haskell似乎有几个可用的优先级队列实现。 例如,有: Data.PriorityQueue.FingerTree(在fingertree-0.0.1.0上hackage) Data.PurePriorityQueue(在纯优先级队列-0.14上的hackage) 这两者看起来都是纯粹的优先队列数据结构。 前者基于手指树,这是我不熟悉的数据结构; 后者是Data.Map的一个包装。 还有 Data.Heap(在hackage中的堆-1.0.0) 它定义了纯粹功能性的堆数据结构,从中可以轻松地制定优先级队列。
I've been recently teaching myself about the Free monad from the free package, but I've come across a problem with it. I would like to have different free monads for different libraries, essentially I would like to build DSLs for different contexts, but I would also like to be able to combine them together. As an example: {-# LANGUAGE DeriveFunctor #-} module TestingFree where import
我最近一直在教自己关于免费软件包中的Free monad,但是我遇到了一个问题。 我想为不同的图书馆提供不同的免费monad,本质上我想为不同的上下文构建DSL,但我也希望能够将它们结合在一起。 举个例子: {-# LANGUAGE DeriveFunctor #-} module TestingFree where import Control.Monad.Free data BellsF x = Ring x | Chime x deriving (Functor, Show) type Bells = Free BellsF data WhistlesF x = PeaWh
Is using unsafePerformIO to allow read-only IO calls to non-changing files in pure code appropriate or is it going to cause a lot of problems? The main reason is because I'd like to store them in containers and for example, make them an instance of Ord , but I can't seem to imagine how to do that without wrapping IO calls in unsafePerformIO . On safety Using unsafePerformIO in the w
是否正在使用unsafePerformIO来允许只读IO调用适当的纯代码中的不变文件,否则会导致很多问题? 主要原因是因为我想将它们存储在容器中,例如使它们成为Ord一个实例,但我似乎无法想象如何在不将unsafePerformIO IO调用包装的情况下这样做。 关于安全 按照您描述的方式使用unsafePerformIO不应引起任何问题。 拇指规则是:如果您使用unsafePerformIO来定义一个可以在Haskell中定义的函数,那么您就可以安全地使用它。
So there's a library in Haskell called spoon which lets me do this safeHead :: [a] -> Maybe a safeHead = spoon . head but it also lets me do this >>> spoon True :: Maybe Bool Just True >>> spoon (error "fork") :: Maybe Bool Nothing >>> spoon undefined :: Maybe Bool Nothing >>> spoon (let x = x in x) :: Maybe Bool <... let's jus
所以Haskell有一个叫做汤匙的库,可以让我这样做 safeHead :: [a] -> Maybe a safeHead = spoon . head 但它也让我这样做 >>> spoon True :: Maybe Bool Just True >>> spoon (error "fork") :: Maybe Bool Nothing >>> spoon undefined :: Maybe Bool Nothing >>> spoon (let x = x in x) :: Maybe Bool <... let's just keep waiting...> 这在某些情况
What are some open source programs that use Haskell and can be considered to be good quality modern Haskell? The larger the code base, the better. I want to learn from their source code. I feel I'm past the point of learning from small code examples, which are often to esoteric and small-world. I want to see how code is structured, how monads interact when you have a lot of things going
什么是使用Haskell的一些开源程序,可以被认为是高质量的现代Haskell? 代码越大越好。 我想从他们的源代码中学习。 我觉得我已经超越了从小代码范例中学习的经验,这些代码范例往往是深奥的小世界。 我想看看代码是如何构建的,当有很多事情发生时(记录,I / O,配置等)monad如何进行交互。 我推荐的。 在20世纪90年代由不同研究生院的人员阅读代码 牛津风格 格拉斯哥风格或(这) 查尔莫斯风格(或这个)
This question already has an answer here: Why is GHC complaining about non-exhaustive patterns? 3 answers GHC simply doesn't know that one of a > b , a < b , or a == b must evaluate to True . (Indeed, it is possible to write an Ord instance that violates this assumption -- though most programmers would not consider doing so, and certainly the one for Int will behave nicely in this
这个问题在这里已经有了答案: GHC为什么抱怨非穷举模式? 3个答案 GHC根本不知道a > b , a < b或a == b必须评估为True 。 (事实上,编写一个违反这个假设的Ord实例是可能的 - 尽管大多数程序员不会考虑这样做,当然Int实例在这方面会表现得很好。) 你可以很明显地看到,GHC已经通过使用完整的模式匹配来覆盖所有的情况,例如 respond correct guess = case compare guess correct of GT -> ... L
Perhaps it's just better to describe my problem. I'm developing a Haskell library. But part of the library is written in C, and another part actually in raw LLVM. To actually get GHC to spit out the code I want I have to follow this process: Run ghc -emit-llvm on both the code that uses the Haskell module and the "Main" module. Run clang -emit-llvm on the C file Now I&
也许这只是描述我的问题。 我正在开发一个Haskell库。 但是库的一部分是用C语言编写的,而另一部分是用原始LLVM编写的。 要真正让GHC吐出我想要的代码,我必须遵循这个过程: 在使用Haskell模块和“Main”模块的代码上运行ghc -emit-llvm 。 在C文件上运行clang -emit-llvm 现在我已经从上面获得了三个.ll文件。 我添加了我在原始LLVM中手写的库的一部分,并将它们llvm-link到一个.ll文件中。 然后我跑LLVM的opt上链
An answer to my previous question indicated that Haskell represents plusWord2# as llvm.uadd.with.overflow . I'm looking to do long addition with carry, like how the x86 ADC instruction works. This instruction not only adds it's two arguments, but also adds the contents of the carry bit. One can then add long numbers like the following: ADD x1 y1 ADC x2 y2 ADC x3 y3 ... Resulting in
对我之前问题的回答表明,Haskell将plusWord2#表示为llvm.uadd.with.overflow 。 我希望能够像x86 ADC指令的工作原理那样进行长时间添加。 该指令不仅增加了两个参数,还增加了进位位的内容。 然后可以添加如下所示的长数字: ADD x1 y1 ADC x2 y2 ADC x3 y3 ... 每个单词产生一个指令(无需任何周围的移动等)。 我查看了GMP库,以及它是如何在其通用C代码中进行长时间添加的。 这是mpn/generic/add_n.c的摘录 sl = ul