Idris : Is it possible to rewrite all functions using “with” to use “case” instead of “with” ? If not, could you give a counter example?

六眼飞鱼酱① 提交于 2019-12-01 18:03:52

问题


In Idris, is it possible to rewrite all functions using "with" to use "case" instead of "with" ?

If not, could you give a counter example ?


回答1:


Not possible. When you pattern match with with, the types in the context are updated with information extracted from the matched constructor. case doesn't cause such updating.

As an example, the following works with with but not with case:

import Data.So

-- here (n == 10) in the goal type is rewritten to True or False
-- after the match
maybeTen : (n : Nat) -> Maybe (So (n == 10))
maybeTen n with (n == 10)
  maybeTen n | False = Nothing
  maybeTen n | True  = Just Oh

-- Here the context knows nothing about the result of (n == 10)
-- after the "case" match, so we can't fill in the rhs
maybeTen' : (n : Nat) -> Maybe (So (n == 10))
maybeTen' n = case (n == 10) of
  True  => ?a 
  False => ?b


来源:https://stackoverflow.com/questions/35610366/idris-is-it-possible-to-rewrite-all-functions-using-with-to-use-case-inste

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!