说我有以下类型类
class Silly (t :: * -> *) where
-- details
Run Code Online (Sandbox Code Playgroud)
我希望能够表达以下约束,但我不确定它是否可能.
class (Silly s) => Willy (s t) where
-- details
Run Code Online (Sandbox Code Playgroud)
基本上我想对类型构造函数设置约束,而不是整个类型.这甚至可以表达吗?我甚至不确定这种约束会被称为什么,所以谷歌一直没有帮助.
编辑:我有一个数据类型
data Reasoner logic atoms a = Reasoner { unReasoner :: MassAssignment atoms -> a }
Run Code Online (Sandbox Code Playgroud)
有一个Applicative实例.我最初有一个run函数,以便使这些Reasoners更容易,但由于我想利用应用程序的自由可组合性,我定义了一个包含的类型run,ala
class RunReasoner r where
type MassType r
type ResultType r
run :: r -> MassType r -> ResultType r
Run Code Online (Sandbox Code Playgroud)
具有以下实例
instance RunReasoner (Reasoner l as a) where
type MassType (Reasoner l as a) = …Run Code Online (Sandbox Code Playgroud) 关于管理.exe文件生成中的unicode字符的第一个问题,这也是GHC中的一个错误?
> print "Frère"
"Fr\233re"
Run Code Online (Sandbox Code Playgroud) 假设我有一个整数列表 l = [1,2]
我要打印到哪个stdout.
做print l产品[1,2]
说我想打印没有大括号的列表
map print l 产生
No instance for (Show (IO ())) arising from a use of `print'
Possible fix: add an instance declaration for (Show (IO ()))
In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)
`:打印
print :: Show a => a -> IO ()
Run Code Online (Sandbox Code Playgroud)
因此,虽然我认为这可行,但我继续尝试:
map putStr $ map show l
Run Code Online (Sandbox Code Playgroud)
因为我怀疑从Integer到String的类型不匹配是罪魁祸首.这产生了与上面相同的错误消息.
我意识到我可以做一些事情,比如将列表连接成一个字符串,但我想尽可能避免这种情况.
这是怎么回事?如何在不从List的元素构造字符串的情况下执行此操作?
我正在尝试使用GHC构建一个静态二进制文件,用于在Haskell中编写的基于CGI的Web应用程序,以部署在共享服务器上.
不幸的是,这不是一件容易的事:
$ ghc -static -optl-static -pgmc musl-gcc -pgml musl-gcc -L/usr/local/lib app.hs
[1 of 1] Compiling Main ( app.hs, app.o )
Linking app...
/usr/lib/ghc-7.6.3/libHSrts.a(Itimer.o): In function `exitTicker':
(.text+0x1af): undefined reference to `__sysv_signal'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?(完全免责声明:我是Haskell新手(:)
我使用的是Arch Linux,GHC 7.6.3和Network.CGI.
这个符号</>在Haskell中意味着什么?
这叫什么?
如何使用它?
我用ghc 7.8来编译应用程序.
为了好玩,我试图编写一个天真最长路径算法的实现(用于在循环图中查找最长非循环路径的长度).我开始使用命令式算法的直接端口,该算法运行良好并且表现相当好.
data Route = Route {dest:: !Int32, cost:: !Int32}
type Node = [Route]
lPathImperative :: V.Vector Node -> Int32 -> UMV.IOVector Bool -> IO (Int32)
lPathImperative !nodes !nodeID !visited = do
UMV.write visited (fromIntegral nodeID) True
max <- newIORef 0
Prelude.mapM_ (\ Route{dest, cost} -> do
isVisited <- UMV.read visited (fromIntegral dest)
case isVisited of
True -> return ()
False -> do
dist <- fmap (+ cost) $ lPathImperative nodes dest visited
maxVal <- readIORef max
if dist > maxVal …Run Code Online (Sandbox Code Playgroud) 我最近开始使用Sublime Text进行编码.这引起了我的注意,当我使用Leksah时,我没有注意到一些警告.所以我得到了这个:
import qualified Data.Set as S
Run Code Online (Sandbox Code Playgroud)
得到:
Warning:
The qualified import of `Data.Set' is redundant
except perhaps to import instances from `Data.Set'
To import instances alone, use: import Data.Set()
Run Code Online (Sandbox Code Playgroud)
另一方面,这两个进口中的Data.Foldable任何一个都没有发出任何警告:
import Data.Foldable (foldrM, mapM_,foldr,foldl',concat)
-- or
import Data.Foldable
Run Code Online (Sandbox Code Playgroud)
所以我不确定Data.Set的警告意味着什么.我希望"多余"意味着它没有必要.如果我删除导入它不会编译,因为我正在为Data.Set使用很多东西.
同时坐在它旁边import qualified Data.Map as M也没有发出警告.
所以我对这个警告所说的完全感到困惑.
我像这样定义了一个类Stack
class Stack stack where
push :: a -> stack a -> stack a
top :: MonadPlus m => stack a -> m (a,stack a)
empty :: stack a
isEmpty :: stack a -> Bool
Run Code Online (Sandbox Code Playgroud)
但是当我实施这些方法时
instance Stack [] where
push b bs = b:bs
top [] = mzero
top (b:bs) = return(b,bs)
empty = []
isEmpty [] = True
isEmpty _ = False
Run Code Online (Sandbox Code Playgroud)
我收到这个警告:
Warning: No explicit implementation for
`Types.push', `Types.top', `Types.empty', and `Types.isEmpty'
In the instance declaration for …Run Code Online (Sandbox Code Playgroud) 我和Haskell和Gtk2Hs有一个奇怪的错误.
我尝试在文本条目中设置光标位置
set entree [entryCursorPosition := 5 ]
Run Code Online (Sandbox Code Playgroud)
对应于Type
entryCursorPosition :: EntryClass self => ReadAttr self Int
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
Couldn't match expected type `()' with actual type `Int'
Run Code Online (Sandbox Code Playgroud)
你认为这是一个错误吗?你知道怎么解决吗?
我在我的Debian Wheezy上用GHC 7.4.1使用Gtk2Hs 0.12.3.
最好的祝福.
我有一个foo带有一连串限制的函数.当然这些约束必须出现在使用的函数的签名中foo,所以我要做的是将foo约束包装在类型同义词中FooCtx a b ... :: Constraint.举个例子,
foo :: (A a, B b, C c, ...) => a -> b -> c
bar :: (A a, B b, C c, ...) ...
bar = ... foo ...
Run Code Online (Sandbox Code Playgroud)
会成为
type FooCtx a b c ... = (A a, B b, C c, ...)
foo :: (FooCtx a b c) => a -> b -> c
bar :: (FooCtx a b c) => ...
Run Code Online (Sandbox Code Playgroud)
如果暴露了所有类型,这将非常有用.但是,我正在使用函数依赖项来生成约束列表中的某些类型,并且这些类型不会出现在签名中 …