该包装建设性代数允许定义代数的实例模块(如矢量空间,但是使用环,其中一个字段是必需的)
这是我尝试定义一个模块:
{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances #-}
module A where
import Algebra.Structures.Module
import Algebra.Structures.CommutativeRing
import Algebra.Structures.Group
newtype A = A [(Integer,String)]
instance Group A where
(A a) <+> (A b) = A $ a ++ b
zero = A []
neg (A a) = A $ [((-k),c) | (k,c) <- a]
instance Module Integer A where
r *> (A as) = A [(r <*> k,c) | (k,c) <- …Run Code Online (Sandbox Code Playgroud) 也许我在这里做了些蠢事,但我得到了:
No instance for (MonadException Ti)
arising from a use of `getInputLine'
Run Code Online (Sandbox Code Playgroud)
在代码示例中:
module Foo where
import System.Console.Haskeline
import System.Console.Haskeline.MonadException
import Control.Monad.State
import Control.Monad.IO.Class
type Ti = StateT Int IO
action :: String -> Ti ()
action s = do
n <- get
lift $ putStrLn $ show n ++ ": " ++ s
repl :: InputT Ti ()
repl = do
minput <- getInputLine "?"
case minput of
Nothing -> return ()
Just input -> lift (action input) >> …Run Code Online (Sandbox Code Playgroud) 我收集了两个数据帧的数据vols和flow.后者可以转换为矩阵,但第一个不是:
as.matrix(vols)
Error in `colnames<-`(`*tmp*`, value = c("CanovesSamalus", "Llinars", :
length of 'dimnames' [2] not equal to array extent
Run Code Online (Sandbox Code Playgroud)
什么是错误?
> vols[1:3,]
data CanovesSamalus Llinars LlinarsCanoves Mirador Santacana StAntoniVilamajor N1 N3 N4 N7 N9
1 2011-01-01 NA 172.66 3779.832 453.096 4996.344 1830.09 9898 9898 9898 9898 9898
2 2011-01-02 NA 172.66 3809.036 494.977 4699.088 1712.43 9898 9898 9898 9898 9898
3 2011-01-03 NA 172.66 3134.215 517.979 4319.374 1716.67 9898 9898 9898 9898 9898
> str(vols)
List …Run Code Online (Sandbox Code Playgroud)