Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

idris

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 ?

like image 286
jhegedus Avatar asked Feb 24 '16 18:02

jhegedus


1 Answers

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
like image 119
András Kovács Avatar answered Sep 20 '22 15:09

András Kovács