i do not know where the empty tuples coming from ? since index is so big, i can not see the content of result
how to remove empty tuples to make it filter to print out all true result?
error:
*Main> let bb = filter (\n -> snd n == True) alltrees1
:74:39:
Couldn't match expected type (a0, Bool)' with actual type()'
Expected type: [(a0, Bool)]
Actual type: [()]
In the second argument of filter', namelyalltrees1'
In the expression: filter (\ n -> snd n == True) alltrees1
run:
:l trees.hs
let allparams = replicateM 3 [1.0, 2.0]
let alltrees = [getAllTrees c | x <- allparams, c <- [x]]
eval(alltrees!!1!!1) == eval(alltrees!!1!!1)
let alltrees1 = forM_ [0..(sizeoflist alltrees)] $ \i -> forM_ [0..(sizeoflist (alltrees!!i))] $ \j -> [(alltrees!!i!!j, eval(alltrees!!i!!j) == eval(alltrees!!i!!j))]
let bb = filter (\n -> if n != () then snd n == True) alltrees1
haskell:
import Data.List
import Control.Monad
import Math.Combinat
import System.IO
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 <- [And, Or]
return $ Mode leftT op rightT
eval :: Mree Double -> Double
eval (Meaf x) = x
eval (Mode l And r) = eval l
eval (Mode l Or r) = eval r
sizeoflist :: [a] -> Int
sizeoflist = length