Incomplete type signature

Lets say we've got a function like f below, that returns a monad. However, where you see Int , pretend it's a really complicated type. f :: (Monad m) => m Int -- Pretend this isn't Int but something complicated f = return 42 Now lets say we want to force this into the Maybe monad. We don't need to write the full type of f to do this, we can just do the following: g :: Maybe a

不完整的类型签名

假设我们有一个如下面的函数f,返回一个单子。 然而,在你看到Int ,假装它是一个非常复杂的类型。 f :: (Monad m) => m Int -- Pretend this isn't Int but something complicated f = return 42 现在让我们说我们想强制这个成Maybe单子。 我们不需要编写完整的f来执行此操作,我们可以执行以下操作: g :: Maybe a -> Maybe a g = id main = print $ (g f) 虚拟函数g迫使f变成Maybe 。 我认为以上是相当混乱。

Haskell: What is Weak Head Normal Form?

What does Weak Head Normal Form (WHNF) mean? What does Head Normal form (HNF) and Normal Form (NF) mean? Real World Haskell states: The familiar seq function evaluates an expression to what we call head normal form (abbreviated HNF). It stops once it reaches the outermost constructor (the “head”). This is distinct from normal form (NF), in which an expression is completely evaluated. You

哈斯克尔:什么是弱头正常形式?

弱头标准形式 (WHNF)是什么意思? 头部正常形式 (HNF)和正常形式 (NF)是什么意思? 真实世界Haskell说: 熟悉的seq函数将表达式评估为我们称之为头标准形式(简称HNF)的表达式。 它一旦到达最外层的构造函数(“头部”)就会停止。 这不同于正常形式(NF),其中表达被完全评估。 您还将听到Haskell程序员提到弱头标准格式(WHNF)。 对于正常数据,弱磁头标准形式与标准标准形式相同。 功能上的区别只在于,而

bit binaries from GHC for Snow Leopard?

I've recently upgraded my OS to Snow Leopard, which broke my GHC. I was able to fix it on one machine by adding flags for 32-bit compiles in /usr/bin/ghc (something like -optl -m32 -opta -m32 -optc -m32, gathered from here). Now I can't get it to produce 64-bit binaries for my other machine, which supports 64-bits. The 32-bit flags break, and removing them breaks as well. Any tips?

GHC for Snow Leopard的二进制文件?

我最近将操作系统升级为Snow Leopard,这打破了我的GHC。 我可以通过在/ usr / bin / ghc中添加用于32位编译的标志(类似于-optl -m32 -opta -m32 -optc -m32,从这里收集到)来修复它在一台机器上。 现在我无法为我的另一台支持64位的机器生成64位二进制文​​件。 32位标志会中断,并将它们删除。 有小费吗? 当我尝试编译时,我得到这样的东西: /var/folders/az/az3Ef9shFZq6RajmTEBwu++++TI/-Tmp-//ghc8006_0/ghc8006_0

Why is `2 + x = 7` valid Haskell?

When I try to compile main = putStrLn $ show x where 2 + x = 7 GHC complains error: Variable not in scope: x | 1 | main = putStrLn $ show x | ^ So it seems that 2 + x = 7 is by itself syntactically valid, although it doesn't actually define x . But why is it so? It is valid because it defines + instead. main = putStrLn (3 + 4) where -- silly redefinit

为什么`2 + x = 7`有效的Haskell?

当我尝试编译 main = putStrLn $ show x where 2 + x = 7 GHC抱怨 error: Variable not in scope: x | 1 | main = putStrLn $ show x | ^ 因此,似乎2 + x = 7本身在句法上是有效的,尽管它实际上并没有定义x 。 但为什么这样呢? 它是有效的,因为它定义了+ 。 main = putStrLn (3 + 4) where -- silly redefinition of `+` follows 0 + y = y x + y = x * ((x-1) + y) 以上

Why is (>>) not defined as (*>)?

GHC currently implements >> as (>>) :: m a -> m b -> m b m >> k = m >>= _ -> k Why not do the following instead? (>>) :: m a -> m b -> m b m >> k = m *> k Right now, I am thinking >>= does something *> doesn't. But everything works out grammatically (as in, type-wise), so it's really hard to reason about why it wouldn

为什么(>>)没有定义为(*>)?

GHC目前实施>>为 (>>) :: m a -> m b -> m b m >> k = m >>= _ -> k 为什么不做以下改为? (>>) :: m a -> m b -> m b m >> k = m *> k 现在,我正在思考>>=做些什么*>没有。 但是,所有的东西都是语法的(例如,类型),所以很难理解它为什么不起作用。 也许monad实例做了一些计算,但应用实例没有,但我认为这会打破该类型的语义。 更新我只能选择一