Comment detail

与えた条件を満たす候補 (Nested Flatten)

	
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
module xop
import StdEnv;($) infixr 1;($) a b :== a b;(>>.) infixl 0;(>>.) a b = \ w -> (\ (_, w) -> b w) (a w);(>>=) infixl 0;(>>=) a b = \ w -> (\ (x, w) -> b x w ) (a w);liftM m :== \ lst -> \ w ->  (m lst, w);join del [x:xs]= (toString x) +++ del +++ (join del xs);join _ [] = "";putStr str = \w -> (stdio >>= liftM ( fwrites str) >>= fclose) w;Start w =snd $ main w;
main = putStr $ join "\n" $ map (join ",") $ xop [And, Or, Not, And]
tf = [True, False]
:: XopOp = And |Or |Not
xopisNot Not = True
xopisNot _ = False
xop :: [XopOp] -> [[Bool]]
xop oplis = foldl (\ knil x  -> if (xopSatisfaction oplis x ) [x:knil] knil) [] $ crossProduct $ take n $ repeat tf  where
    n = length oplis  +  1  -  length (filter xopisNot oplis)
xopSatisfaction x org= lp x org where
    lp [And:Not:xs] [y:y2:ys] = lp xs [y && (not y2):ys]
    lp [And:xs] [y:y2:ys] = lp xs [y && y2:ys]
    lp [Or:Not:xs]  [y:y2:ys] = lp xs [y || (not y2):ys]
    lp [Or:xs]  [y:y2:ys] = lp xs [y || y2:ys]
    lp []  [y:ys]         = y
    lp _  [] = abort "test"
crossProduct x :== cp [] x where
    cp knil [[x:xs]:ys] = (cp knil [xs:ys]) ++ cp [x:knil] ys
    cp knil [[]:ys] =  []
    cp knil [] =  [knil]

Index

Feed

Other

Link

Pathtraq

loading...