haskell

Template Haskell: Is there a function (or special syntax) that parses a String and returns Q Exp?

守給你的承諾、 提交于 2020-01-09 19:46:09
问题 I am trying to learn a bit of Template Haskell and Quasi Quotation, and I am looking for a function that takes a String and parses it to Q Exp , so the type is: String -> Q Exp Tried searching hoogle, but the results I saw had to do with lifting String literals to Q Exp , and the closest I found was Language.Haskell.TH.dyn which does quite what I want, but only for a single variable. Are there other options? E.g. a special syntax? I'm just in the process of familiarizing myself with [||] and

Template Haskell: Is there a function (or special syntax) that parses a String and returns Q Exp?

别来无恙 提交于 2020-01-09 19:44:46
问题 I am trying to learn a bit of Template Haskell and Quasi Quotation, and I am looking for a function that takes a String and parses it to Q Exp , so the type is: String -> Q Exp Tried searching hoogle, but the results I saw had to do with lifting String literals to Q Exp , and the closest I found was Language.Haskell.TH.dyn which does quite what I want, but only for a single variable. Are there other options? E.g. a special syntax? I'm just in the process of familiarizing myself with [||] and

What are the pros and cons of Enumerators vs. Conduits vs. Pipes?

我的梦境 提交于 2020-01-09 12:18:08
问题 I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators, Conduits, and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have a high-level overview. 回答1: Enumerators/Iteratees as an abstraction were invented by Oleg Kiselyov. They provide a clean way of doing IO with predictable (low) resource requirements. The current Enumerators package is pretty close to Oleg's

What are the pros and cons of Enumerators vs. Conduits vs. Pipes?

夙愿已清 提交于 2020-01-09 12:17:50
问题 I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators, Conduits, and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have a high-level overview. 回答1: Enumerators/Iteratees as an abstraction were invented by Oleg Kiselyov. They provide a clean way of doing IO with predictable (low) resource requirements. The current Enumerators package is pretty close to Oleg's

Generating a Truth Table

℡╲_俬逩灬. 提交于 2020-01-09 11:26:48
问题 If I have some values A B C, is is possible to generate a list of all their possible truth values: the input is ["X", "Y", "Z"] e.g. the list contains 8 lists (rows of table) [ [ ("X",True), ("Y",True), ("Z", True) ], [ ("X",True), ("Y",True), ("Z", False) ],.... ] Are there any hints on how to do this? I would like to generate a truth table for an arbitrary number of variables. 回答1: What you need is not a truth table but rather a cartesian product. You can obtain what you want using list

Simplifying a GADT with Uniplate

╄→гoц情女王★ 提交于 2020-01-09 09:49:45
问题 I'm trying to answer this stackoverflow question, using uniplate as I suggested, but the only solution I've come up with so far is pretty ugly. This seems like a fairly common issue, so I wanted to know if there was a more elegant solution. Basically, we've got a GADT which resolves to either Expression Int or Expression Bool (ignoring codataIf = If (B True) codataIf codataIf ): data Expression a where I :: Int -> Expression Int B :: Bool -> Expression Bool Add :: Expression Int -> Expression

Pattern matching variables in a case statement in Haskell

谁说胖子不能爱 提交于 2020-01-09 07:43:07
问题 If I compare a string literal to a string literal using the case statement, I get the expected behavior: if they are the same - it matches, if they are not - it does not. However, if I compare a string literal to a constant that is a string, I get "Pattern matches are overlapped" warning and the branch with the constant always matches. Here's an example session: Prelude> let var1 = "abc" Prelude> let var2 = "def" Prelude> case var1 of { var2 -> "Fail"; _ -> "Win" } <interactive>:1:0: Warning:

Is Haskell's mapM not lazy?

偶尔善良 提交于 2020-01-09 03:49:30
问题 UPDATE: Okay this question becomes potentially very straightforward. q <- mapM return [1..] Why does this never return? Does mapM not lazily deal with infinite lists? The code below hangs. However, if I replace line A by line B, it doesn't hang anymore. Alternatively, if I preceed line A by a "splitRandom $", it also doesn't hang. Q1 is: Is mapM not lazy? Otherwise, why does replacing line A with line B "fix this" code? Q2 is: Why does preceeding line A with splitRandom "solve" the problem?

Find the longest common starting substring in a set of strings [closed]

流过昼夜 提交于 2020-01-08 17:25:31
问题 Closed. This question is off-topic. It is not currently accepting answers. Closed 4 years ago . Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. This is a challenge to come up with the most elegant JavaScript, Ruby or other solution to a relatively trivial problem. This problem is a more specific case of the Longest common substring problem. I need to only find the

Haskell的大规模设计? [关闭]

雨燕双飞 提交于 2020-01-07 21:31:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 设计/构建大型功能程序的好方法是什么,特别是在Haskell中? 我已经阅读了很多教程(自己编写一个方案是我最喜欢的,Real World Haskell紧随其后) - 但是大多数程序都相对较小,而且是单一目的。 另外,我不认为它们中的一些特别优雅(例如,WYAS中的大量查找表)。 我现在想要编写更大的程序,包含更多移动部件 - 从各种不同来源获取数据,清理数据,以各种方式处理数据,在用户界面中显示,持久化,通过网络进行通信等。一个最好的结构,这样的代码是易读,可维护,并适应不断变化的要求? 有大量文献针对大型面向对象的命令式程序解决了这些问题。 像MVC,设计模式等的想法是实现广泛目标的理想规定,例如在OO风格中分离关注点和可重用性。 此外,较新的命令式语言适合于“随着您的成长而设计”的重构风格,在我的新手看来,Haskell似乎不太适合。 Haskell有相同的文献吗? 如何在功能性编程(单子,箭头,应用等)中使用异域控制结构的动物园最好地用于此目的? 你能推荐什么最佳实践? 谢谢! 编辑(这是Don Stewart回答的后续行动): @dons提到:“Monads在类型中捕获关键的建筑设计。” 我想我的问题是:如何在纯函数式语言中考虑关键的架构设计? 考虑几个数据流的示例和几个处理步骤。