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 1924
不思量自难忘°
不思量自难忘° 2021-01-18 18:23

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条回答
  • 2021-01-18 18:53

    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
    
    0 讨论(0)
提交回复
热议问题