例外:Prelude。(!!):索引太大错误

时间:2015-08-17 16:49:56

标签: haskell

UPDATE1:

尝试了一种新的方式来做二维阵列访问后,它不能使用支架括号

let allparams = replicateM 3 [1.0, 2.0, 3.0]
let alltrees = [getAllTrees c | x <- allparams, c <- [x]]
let alltrees1 = [b | c <- alltrees | x <- [c] | b <- [d | ee <- alltrees | y <- [ee] | d <- ((x,y), eeval1(x) >= eeval1(y) && eeval2(x) >= eeval2(y) && eeval3(x) >= eeval3(y) && eeval4(x) >= eeval4(y))]]


<interactive>:8:36:
    Unexpected parallel statement in a list comprehension
    Use -XParallelListComp

<interactive>:8:44: Not in scope: `c'

<interactive>:8:74:
    Unexpected parallel statement in a list comprehension
    Use -XParallelListComp

<interactive>:8:82:
    Not in scope: `ee'
    Perhaps you meant one of these:
      `e' (imported from Math.Algebras.VectorSpace),
      e' (imported from Math.Algebras.VectorSpace),
      `e1' (imported from Math.Algebras.VectorSpace)

<interactive>:8:95: Not in scope: `x'

<interactive>:8:97: Not in scope: `y'

<interactive>:8:108: Not in scope: `x'

<interactive>:8:121: Not in scope: `y'

<interactive>:8:134: Not in scope: `x'

<interactive>:8:147: Not in scope: `y'

<interactive>:8:160: Not in scope: `x'

<interactive>:8:173: Not in scope: `y'

<interactive>:8:186: Not in scope: `x'

<interactive>:8:199: Not in scope: `y'

在load:l trees.hs之后运行以下代码时出错 当列出(树方程式,真或假)时 并将筛选true或false以显示树方程式

之前,在列表之后,它有错误

let allparams = replicateM 3 [1.0, 2.0, 3.0]
let alltrees = [getAllTrees c | x <- allparams, c <- [x]]
let alltrees1 = forM_ [1..(sizeoflist alltrees)] $ \i -> forM_ [1..(sizeoflist (alltrees!!i))] $ \j -> [(alltrees!!i!!j, eeval1(alltrees!!i!!j) > eeval1(alltrees!!i!!j) && eeval2(alltrees!!i!!j) > eeval2(alltrees!!i!!j) && eeval3(alltrees!!i!!j) > eeval3(alltrees!!i!!j) && eeval4(alltrees!!i!!j) > eeval4(alltrees!!i!!j))]

错误,如何在项目过大时显示项目

*Main> alltrees1!!0
*** Exception: Prelude.(!!): index too large

trees.hs

import Data.List
import Data.Array
--import Data.Set
--import Data.Graph 
import Control.Monad
import Math.Combinat
import Math.Core.Utils
import Math.Core.Field
import Math.Algebras.VectorSpace
import Math.Algebras.Structures
--import Math.CommutativeAlgebra.GroebnerBasis
--import Math.CommutativeAlgebra.Polynomial
--import Math.Algebras.Matrix
import System.IO
import qualified Data.Map as M

type Vertex = Int
type Table a = Array Vertex a
type Graph e = Table [(e, Vertex)]
type Bounds  = (Vertex, Vertex)
type Edge e = (Vertex, e, Vertex)

type Labeling a = Vertex -> a
data LabGraph n e = LabGraph (Graph e) (Labeling n)

data Operation
  = And
  | Or
  | MA
  | MB
  | Impl
    deriving Show

data Mree x
 = Meaf x
 | Mode (Mree x) Operation (Mree x)
   deriving Show

splits :: [a] -> [([a], [a])]
splits xs = zip (inits xs) (tails xs)

getAllTrees :: [a] -> [Mree a]
getAllTrees [] = []
getAllTrees [x] = return $ Meaf x
getAllTrees xs = do
  (left, right) <- splits xs
  guard $ not (null left) && not (null right)
  leftT <- getAllTrees left
  rightT <- getAllTrees right
  op <- [MA, MB, And, Or]
  return $ Mode leftT op rightT

eeval1 :: Mree Double -> Double
eeval1 (Meaf x) = x
eeval1 (Mode l And r) = eeval1 l * eeval1 r
eeval1 (Mode l Or r) = eeval1 l + eeval1 r
eeval1 (Mode l MA r) = eeval1 l + eeval1 r
eeval1 (Mode l MB r) = eeval1 l + eeval1 r

eeval2 :: Mree Double -> Double
eeval2 (Meaf x) = x
eeval2 (Mode l And r) = eeval2 l * eeval2 r
eeval2 (Mode l Or r) = eeval2 l + eeval2 r
eeval2 (Mode l MA r) = eeval2 l + eeval2 r
eeval2 (Mode l MB r) = eeval2 l * eeval2 r

eeval3 :: Mree Double -> Double
eeval3 (Meaf x) = x
eeval3 (Mode l And r) = eeval3 l * eeval3 r
eeval3 (Mode l Or r) = eeval3 l + eeval3 r
eeval3 (Mode l MA r) = eeval3 l * eeval3 r
eeval3 (Mode l MB r) = eeval3 l + eeval3 r

eeval4 :: Mree Double -> Double
eeval4 (Meaf x) = x
eeval4 (Mode l And r) = eeval4 l * eeval4 r
eeval4 (Mode l Or r) = eeval4 l + eeval4 r
eeval4 (Mode l MA r) = eeval4 l * eeval4 r
eeval4 (Mode l MB r) = eeval4 l * eeval4 r

sizeoflist :: [a] -> Int
sizeoflist = length

0 个答案:

没有答案