If Then Else の定義のプロジェクションに問題があります。実際には If-Else-Then として実行されています。
import Prelude hiding (pred,and,or,not)
data PR = Z
| S
| P Int
| C PR [PR]
| PR PR PR
deriving Show
eval :: PR -> [Integer] - Integer
eval Z _ = 0
eval S [x] = x+1
eval (P n) xs = nth n xs
eval (C f gs) xs = eval f (map (\g -> eval g xs) gs)
eval (PR g h) (0:xs) = eval g xs
eval (PR g h) (x:xs) = eval h ((x-1) : eval (PR g h) ((x-1):xs) : xs)
nth _ [] = error "nth nil"
nth 0 _ = error "nth index"
nth 1 (x:_) = x
nth (n) (_:xs) = nth (n-1) xs
one = C S [Z]
plus = PR (P 1) (C S [P 2])
ife = PR (P 1) (C (P 2) [P 3, P 4])
スワップしようとするP 3
と、P 4
完全に壊れます(毎回「then」値を返します)。ite[0,2,3]
戻る必要があり、戻る必要が3
あります。代わりに、反対のことが起こっています。どうすればこれを修正できますか?ite[1,2,3]
2