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 ?
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