Partial type signature

Possible Duplicate: Incomplete type signature Consider the following: import Network.HTTP.Conduit (parseUrl "http://stackoverflow.com") :: Maybe a parseUrl returns Failure HttpException m => m (Request m') It's documentation says: Since this function uses Failure , the return monad can be anything that is an instance of Failure , such as IO or Maybe . However, when I try

部分类型签名

可能重复: 不完整的类型签名 考虑以下: import Network.HTTP.Conduit (parseUrl "http://stackoverflow.com") :: Maybe a parseUrl返回Failure HttpException m => m (Request m') 它的文档说: 由于此函数使用Failure ,返回的monad可以是任何Failure的实例,例如IO或Maybe 。 但是,当我尝试强制parseUrl使用Maybe ,出现以下错误: main.hs:9:11: Couldn't match type `a' with `Request m'0'

How to define function signatures partially in Haskell?

Starting point: fn :: [a] -> Int fn = (2 *) . length Let's say we only want to constrain the return value, then we could write: fn list = (2 * length list) :: Int How about restricting only the argument? Easy. fn list = 2 * length (list :: [Char]) While this works, it would be preferable to have the signatures at the top collected and not scattered around the function body. This i

如何在Haskell中部分定义函数签名?

初始点: fn :: [a] -> Int fn = (2 *) . length 假设我们只想限制返回值,那么我们可以这样写: fn list = (2 * length list) :: Int 如何限制只有论点? 简单。 fn list = 2 * length (list :: [Char]) 虽然这是有效的,但最好将顶部的签名收集起来,而不是散布在函数体的周围。 这是我能接近的最接近的: fnSig = undefined :: [Char] -> a fn | False = fnSig | True = (* 2) . length 基于http://okmi

Test if a value has been evaluated to weak head normal form

In Haskell, is it possible to test if a value has been evaluated to weak head normal form? If a function already exists, I would expect it to have a signature like evaluated :: a -> IO Bool There are a few places that similar functionality lives. A previous answer introduced me to the :sprint ghci command, which will print only the portion of a value that has already been forced to weak h

测试一个值是否被评估为弱头标准形式

在Haskell中,是否有可能测试一个值是否被评估为弱头标准形式? 如果一个函数已经存在,我希望它有一个签名 evaluated :: a -> IO Bool 有一些类似功能的地方。 先前的回答向我介绍了:sprint ghci命令,它将只打印已经被强制为弱头标准格式的那部分值。 :sprint可以观察一个值是否被评估过: > let l = ['a'..] > :sprint l l = _ > head l 'a' > :sprint l l = 'a' : _ IO可能会检查否则将被禁止的属性

What does “⊥” mean in “The Strictness Monad” from P. Wadler's paper?

Can someone help me understand the following definition from Wadler's paper titled "Comprehending Monads"? (Excerpt is from section 3.2/page 9, ie, the "Strictness Monad" subsection.) Sometimes it is necessary to control order of evaluation in a lazy functional program. This is usually achieved with the computable function strict, defined by strict fx = if x ≠ ⊥ then

P. Wadler的论文中的“严格单子”中的“⊥”是什么意思?

有人能帮助我理解Wadler的题为“理解单子”的论文中的下列定义吗? (摘录来自3.2节/第9页,即“严格单子”小节。) 有时候需要在懒惰的功能程序中控制评估顺序。 这通常是通过严格定义的可计算函数来实现的 严格的fx =如果x≠⊥然后fx else⊥。 在操作上,通过首先将x减小到弱头标准形式(WHNF)然后减小应用f x来减小严格的fx。 或者,可以并行减少x和fx,但在x处于WHNF之前不允许访问结果。 在这篇论文中,我们还没有看到

Weak head normal form and order of evaluation

I've read lots on weak head normal form and seq. But I'm still have trouble imagining the logic behind Haskell's order of evaluation A common example demonstrating when and how to use but I still don't understand how the common example foldl (+) 0 [1..5000000] can result in a stack overflow. While another fold definition using seq doesn't foldl' _ a [] = a foldl' f a (x

弱首标的形式和评价顺序

我读了很多弱头正常形式和seq。 但是我仍然很难想象Haskell的评估顺序背后的逻辑 一个常见的例子说明何时以及如何使用,但我仍然不明白常见的例子 foldl (+) 0 [1..5000000] 可能导致堆栈溢出。 而使用seq另一个折叠定义不会 foldl' _ a [] = a foldl' f a (x:xs) = let a' = f a x in a' `seq` foldl' f a' xs foldl' (+) 0 [0..5000000] 从我读过的seq的解释中,作者非常谨慎地阐明以下内容: seq的第一个参数不保证

strict and lazy differ?

I often read that lazy is not the same as non-strict but I find it hard to understand the difference. They seem to be used interchangeably but I understand that they have different meanings. I would appreciate some help understanding the difference. I have a few questions which are scattered about this post. I will summarize those questions at the end of this post. I have a few example snip

严格和懒惰不同?

我经常读到, 懒惰与非严格不一样,但我发现很难理解这种差异。 它们似乎可以互换使用,但我知道它们有不同的含义。 我希望有助于理解差异。 我有几个关于这篇文章的问题。 我将在这篇文章结尾总结这些问题。 我有几个示例片段,我没有测试它们,我只是将它们作为概念呈现。 我已经添加了引号以避免您查找它们。 也许它会在稍后提出同样的问题。 非严格防卫: 函数f被认为是严格的,如果应用于非终止表达式时,它也

Haskell, Measuring CPU time of a function

I need to measure CPU time of a function like following: t <- getCPUTime res <- callTheFunction input t' <- getCPUTime print $ t' - t The problem comes from the laziness of Haskell. callTheFunction must be strictly evaluated. I've searched a lot and tried to use seq and $! but without success. I think this should be a quite common task. Anyway, I need some help. Thanks. Upd

Haskell,测量函数的CPU时间

我需要测量如下函数的CPU时间: t <- getCPUTime res <- callTheFunction input t' <- getCPUTime print $ t' - t 问题来自Haskell的懒惰。 callTheFunction必须严格评估。 我搜索了很多,并尝试使用seq和$! 但没有成功。 我认为这应该是一个相当普遍的任务。 无论如何,我需要一些帮助。 谢谢。 更新:感谢所有帮助,特别是@FUZxxl。 它让我想起了WHNF(弱首标准形式)和正常形式之间的区别。 Haskell /

Are monad laws enforced in Haskell?

From the Haskell wiki: Monads can be viewed as a standard programming interface to various data or control structures, which is captured by the Monad class. All common monads are members of it: class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a fail :: String -> m a In addition to implementing the class

Haskell是否实施单子法?

来自Haskell wiki: Monad可以被看作是Monad类捕获的各种数据或控制结构的标准编程接口。 所有常见的monad都是它的成员: class Monad m where (>>=) :: m a -> (a -> m b) -> m b (>>) :: m a -> m b -> m b return :: a -> m a fail :: String -> m a 除了实现类函数外,Monad的所有实例都应遵守以下等式或Monad Laws: return a >>= k = k a m >>= return = m

When to use Haskell monads

I'm implementing a combinatorial optimization algorithm in Haskell: Given an initial candidate solution, repeat until stopping criteria are met: 1. Determine possible moves 2. Evaluate possible moves 3. Choose a move 4. Make move, record new candidate solution, update search state I could write functions for steps 1-4 and chain them together inside a recursive function to handle lo

何时使用Haskell monad

我在Haskell中实现了一个组合优化算法: Given an initial candidate solution, repeat until stopping criteria are met: 1. Determine possible moves 2. Evaluate possible moves 3. Choose a move 4. Make move, record new candidate solution, update search state 我可以编写第1-4步的函数,并将它们链接在一个递归函数中,以处理循环和从一个迭代到下一个迭代的状态,但我有一个模糊的想法,monads适用。

What haskell topics need to be addressed in a Real

It has been quite some time now that RWH came out ( almost 3 years ). I was eager to get my copy after following the incremental writing of the book online (which is, I think, one of the best ways to write a book.) What a rewarding read in the midst of all the rather academic papers a haskell student usually encounters! It was a sturdy companion on quite some trips and I refer back to it regul

什么Haskell主题需要在Real中解决

RWH出来已经有相当长的一段时间了( 近3年 )。 在网络书的增量写作之后(我认为这是编写一本书的最佳方式之一)之后,我急于获得我的副本。在所有学术论文中,哈斯克尔学生通常遇到! 这在一些旅行中是一个坚强的伴侣,我经常回顾它。 尽管如此,我的副本开始看起来很憔悴,尽管大部分内容仍然有效,但在Haskell世界中有很多新的主题值得以类似的方式进行讨论。 考虑到RWH的影响力(现在仍然存在),我真心希望有一天会有