相关疑难解决方法(0)

$(美元)和$之间有什么区别!(美元感叹号)

任何人都可以解释Haskell在运算符($)($!)(美元符号与美元符号感叹号)之间的区别吗?

$!到目前为止,我还没有看到任何地方的使用,但在浏览Haskell 参考时,我注意到它的存在,并且它具有完全相同的定义$.在Haskell解释器(GHCi)中尝试一些简单的语句时,我找不到任何差异,在搜索时也无法在列出的顶级教程中找到对运算符的任何引用haskell tutorial.

所以,出于好奇,有什么区别,如果有的话?

syntax haskell

27
推荐指数
2
解决办法
5960
查看次数

如何在"where"子句中赋予表达式泛型类型?

(请原谅可怕的人为例子)

我想要做的是在where子句中指定类型:

somemap :: (a -> b) -> [a] -> [b]
somemap f xs = ys
  where
    some = take 5 xs :: [a]
    ys = map f some :: [b]
Run Code Online (Sandbox Code Playgroud)

但这会导致错误:

*Main> :load file.hs 
[1 of 1] Compiling Main             ( file.hs, interpreted )

fil.hs:15:18:
    Couldn't match expected type `a1' against inferred type `a'
      `a1' is a rigid type variable bound by
           an expression type signature at file.hs:15:25
      `a' is a rigid type variable bound by
          the type signature for …
Run Code Online (Sandbox Code Playgroud)

generics haskell types where-clause type-declaration

7
推荐指数
1
解决办法
351
查看次数