评估有效功能,给出意想不到的结果

时间:2017-09-01 23:54:33

标签: effects idris

标题是相当自我解释的。使用this paper作为参考,我一直在研究如何在Idris中正确使用效果。创建有效的函数似乎很简单,但对有效函数的实际评估给出了我不期望的结果。对于上下文,如果我有以下程序:

h1 : Eff Nat [SYSTEM, RND]
h1 = do srand !time
        pure (fromInteger !(rndInt 0 6))

h2 : Eff Nat [SYSTEM]
h2 = pure (fromInteger !time)

h3 : Eff Nat [RND]
h3 = do srand 123456789
        pure (fromInteger !(rndInt 0 6))

runH : IO ()
runH = do
    x <- run h1            -- <---- This one works fine
    --let x = runPure h1   -- <---- This one does not work  << !!!
    y <- run h2            -- <---- This one works fine
    --let y = runPure h2   -- <---- This one does not work  << !!!
    --z <- run h3          -- <---- This one works fine
    let z = runPure h3     -- <---- This one works fine     << ???

    putStrLn $
      "test 1 : " ++ show x ++ "\n" ++
      "test 2 : " ++ show y ++ "\n" ++
      "test 3 : " ++ show z

我希望能够用runPure从h1,h2和h3中获取实际值,但编译器只允许我为h3执行此操作。 h1和h2只有在使用run进行评估时才会编译。我看到的唯一真正差异是a)具有多重效果的功能无法使用runPure或b)SYSTEM效果无法使用runPure。任何人都可以向我解释为什么上面的代码行为方式呢?

如果我在let y = runPure h2上选择y <- run h2行,则会出现完整错误:

When checking right hand side of runH with 
expected type 
    IO ()
When checking argument env to function Effects.runPure:
Type mismatch between
    Env m [] (Type of [])
and
    Env id [SYSTEM] (Expected type)

Specifically:
Type mismatch between
    []
and
    [SYSTEM]

0 个答案:

没有答案