我已经将类型定义X为
newtype X i o = X { runX :: Int -> i -> IO o }
Run Code Online (Sandbox Code Playgroud)
我已经做的一个实例Functor,Applicative并Monad用
instance Functor (X i) where
fmap f a = X $ \ i o -> liftA f $ runX a i o
instance Applicative (X i) where
pure x = X $ \ _ _ -> return x
a <*> b = X $ \ i o -> liftA2 (<*>) (runX a i o) …Run Code Online (Sandbox Code Playgroud) 我导入了一个数据类型X,定义为
data X a = X a
Run Code Online (Sandbox Code Playgroud)
在本地,我已经定义了一个通用量化的数据类型, Y
type Y = forall a. X a
Run Code Online (Sandbox Code Playgroud)
现在我需要定义两个函数,toY和fromY.因为fromY,这个定义工作正常:
fromY :: Y -> X a
fromY a = a
Run Code Online (Sandbox Code Playgroud)
但如果我尝试同样的事情toY,我会收到错误
Couldn't match type 'a' with 'a0'
'a' is a rigid type variable bound by the type signature for 'toY :: X a -> y'
'a0' is a rigid type variable bound by the type signature for 'toY :: X a -> X …Run Code Online (Sandbox Code Playgroud) 我正在使用FRP.Sodium,我有一个类型的对象IO (Behavior (IO (Behavior))).我需要IO (Behavior)使用类似于嵌套的东西将该对象转换为类型join.这是否可以使用钠功能?是否有更通用的解决方案a (b (a (b c))) -> a (b c))?
是否存在>>=两个参数的函数?就像是
bind2 :: m a -> m b -> (a -> b -> m c) -> m c
Run Code Online (Sandbox Code Playgroud) 我一直在搞乱一个简单的张量库,我在其中定义了以下类型.
data Tensor : Vect n Nat -> Type -> Type where
Scalar : a -> Tensor [] a
Dimension : Vect n (Tensor d a) -> Tensor (n :: d) a
Run Code Online (Sandbox Code Playgroud)
该类型的矢量参数描述了张量的"尺寸"或"形状".我目前正在尝试定义一个安全索引到a的函数Tensor.我本来打算用Fins 做这个,但我遇到了一个问题.因为Tensor序列未知,我可能需要任意数量的索引,每个索引都需要不同的上限.这意味着一个Vect索引不足,因为每个索引都有不同的类型.这让我开始考虑使用元组(在Idris中称为"对"?).我编写了以下函数来计算必要的类型.
TensorIndex : Vect n Nat -> Type
TensorIndex [] = ()
TensorIndex (d::[]) = Fin d
TensorIndex (d::ds) = (Fin d, TensorIndex ds)
Run Code Online (Sandbox Code Playgroud)
这个函数按照我的预期工作,从维度向量计算适当的索引类型.
> TensorIndex [4,4,3] -- (Fin 4, Fin 4, Fin 3)
> TensorIndex [2] -- …Run Code Online (Sandbox Code Playgroud) 我没有找到如何用 kivy 语言强制窗口大小。(例如:800x600p)
你能帮助我吗 ?
谢谢阅读。
PITO2901
我在Haskell玩耍时发现了一些奇怪的东西.我在下面定义了一个简单的提示函数.
-- file: test.hs
main :: IO ()
main = putStrLn . ("Hello, " ++) =<< (putStr "Name: " >> getLine)
Run Code Online (Sandbox Code Playgroud)
当我runhaskell这样,它按预期工作,打印提示,等待我的输入,然后打印问候语.
$ runhaskell test.hs
Name: kwarrtz
Hello, kwarrtz
Run Code Online (Sandbox Code Playgroud)
然而,当我编译它时,事情变得奇怪.当我运行它时,它不会打印提示,而是给我一个空行并等待输入.当我输入我的名字并按Enter键时,它会在同一行打印提示和问候语.换句话说,getLine发生在之前putStr.
$ ghc test.hs
$ ./test
kwarrtz
Name: Hello, kwarrtz
Run Code Online (Sandbox Code Playgroud)
对发生了什么的任何想法?我想它与终端上的线路缓冲有关,但我不确定(我或者我在代码中犯了一些非常荒谬的错误).
我在Mac OS X El Capitan上运行GHC 7.8.3并使用默认的终端应用程序.