是否有组合器可以以 pointfree 风格编写 Haskell 类型?
我有一个类似的类型同义词:
type FooT m a = StateT State (ReaderT (Params m) m)
Run Code Online (Sandbox Code Playgroud)
我希望能够以 pointfree 风格编写它的右侧,以便实例化一个需要参数为 monad 转换器的类型类。即,有一些类型类,例如:
class (MonadTrans t, Bar (t Monad)) => Baz t where -- where Bar is some other typeclass
...
Run Code Online (Sandbox Code Playgroud)
我想用我的变压器堆栈实例化它。但是,我需要向它提供某种类型的东西(* -> *) -> * -> *,这意味着我需要编写一个类型级函数,以便将我的StateT State (ReaderT ...)转换器作为参数传递给类型类。
我尝试使用类型系列,但似乎它们需要完全应用。
我有一个我无法弄清楚的错误.使用Haskell Platform 2010,GHC 6.12,系统为10.5(32位)
考虑以下:
loop :: IO ()
loop = do
return ()
loop
main = do
loop
Run Code Online (Sandbox Code Playgroud)
编译时,
ghc --make test.hs
Run Code Online (Sandbox Code Playgroud)
此代码最终占用了CPU的100%时间.这是为什么?你如何在Haskell中编写一个程序,像这样循环,同时对笔记本电脑的电池很好?
并发的"收益"似乎没有做任何有趣的事情.
我开始学习Haskell了.即使我是一个非凡的笨蛋,我也打算做这项工作.我收到的错误列为标题.这是我编写的代码,用于尝试实现复制列表(n)次并将其新长度连接为新列表的行为.现在我基本了解了解析在Haskell中是如何工作的,在我的原始代码下面,我将给出一些修改过的代码示例,看看我对解析的理解是否足够.我现在的问题是如何正确地缩进或构造我的块以便不接收此错误(这是特定的:O) - 在创建实例和格式时,我是否缺少一些信息?如果您注意到我的当前实体或主要功能是完全错误的,请不要告诉我或提出建议.我想弄明白,并且当我到达它时将处理GHC错误.(我希望这是正确的学习方式).但是,如果我可以请求任何人的帮助来解决理解正确格式的第一个障碍,我将不胜感激.
module Main where
import Data.List
n :: Int
x :: [Char]
instance Data stutter n x where
x = []
n = replicate >>= x : (n:xs)
stutter >>= main = concat [x:xs]
let stutter 6 "Iwannabehere" -- <-- parse error occurs here!!!
Run Code Online (Sandbox Code Playgroud)
- 使用适当的括号修改代码,至少在我认为它们去的地方.
module Main where
import Data.List
n :: Int
x :: [Char]
instance Data stutter n x where{
;x = []
;n = replicate >>= x : (n:xs)
;stutter >>= main = concat …Run Code Online (Sandbox Code Playgroud) 我从Haskell开始,尝试在Haskell中编译.ghci文件时遇到此奇怪的错误消息。我有这个非常简单的代码,例如:
main = do
putStrLn "Greetings! What is your name?"
inpStr <- getLine
putStrLn $ "Welcome to Haskell, " ++ inpStr ++ "!"
Run Code Online (Sandbox Code Playgroud)
我将代码保存在一个名为basicio.hs并尝试运行的文件中,
ghc basicio.hs
而不是字符串,我收到以下消息
<interactive>:2:1: error:
Variable not in scope: runghc :: t0 -> b0 -> c
<interactive>:2:8: error: Variable not in scope: basicio
Run Code Online (Sandbox Code Playgroud)
我不确定出什么问题,命令“:load”可以正常工作并找到我的文件。
是:typeHaskell语言的一部分还是GHC的命令?
前缀:代表的语言不是GHC的一部分吗?
谢谢。
我发现了以下Haskell代码,但我很困惑:
main = putStrLn "Enter 1st String:"
>> getLine
>>= \a -> read a
Run Code Online (Sandbox Code Playgroud)
两个"大于"符号(>>)的含义是什么?一个新的声明?
两个"大于"符号后面跟一个等号(>>=)是什么意思?
此Haskell代码抛出以下错误:
a.hs:3:13:
No instance for (Read (IO t0)) arising from a use of ‘read’
In the expression: read a
In the second argument of ‘(>>=)’, namely ‘\ a -> read a’
In the expression:
putStrLn "Enter 1st String:" >> getLine >>= \ a -> read a
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习Haskell,但它有点难,因为我的绑定不会从命令行记住; 我的终端输出如下.
> let b = []
> b
[]
> 1:b
[1]
> b
[]
Run Code Online (Sandbox Code Playgroud)
我不知道为什么这样可以请任何人帮忙.
我有一个haskell文件:
main = putStrLn "hello world"
let a=1
show a
Run Code Online (Sandbox Code Playgroud)
和ghc说:
main.hs:3:1:
parse error (possibly incorrect indentation or mismatched brackets)
Run Code Online (Sandbox Code Playgroud) 我在构建时遇到此错误:
dist/package.conf.inplace:
inappropriate type
FAILED DURING THE BUILDING PHASE. The **exception** was: ExitFailure 1
Run Code Online (Sandbox Code Playgroud)
如何subRegex 在 Text.Regex 包中使用?
我已经写了:
import Text.Regex.Posix
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
_.hs:13:5: Not in scope: ‘subRegex’
_.hs:13:15:
Not in scope: ‘mkRegex’
Perhaps you meant ‘makeRegex’ (imported from Text.Regex.Posix)
Run Code Online (Sandbox Code Playgroud)
所以,我去了Text.Regex[页] [1],然后说:
使用POSIX正则表达式接口
Text.Regex.Posix.
那么为什么不是这些功能在范围内呢?
ghc ×9
haskell ×9
parsing ×2
binding ×1
command-line ×1
compilation ×1
macos ×1
osx-leopard ×1
regex ×1
scope ×1