gpt4 book ai didi

Idris : Is it possible to rewrite all functions using "with" to use "case" instead of "with" ? 如果不是,你能举个反例吗?

转载 作者:行者123 更新时间:2023-12-04 18:35:38 27 4
gpt4 key购买 nike

在 Idris 中,是否可以使用“with”重写所有函数以使用“case”而不是“with”?

如果不是,你能举个反例吗?

最佳答案

不可能。当您使用 with 进行模式匹配时,上下文中的类型使用从匹配的构造函数中提取的信息进行更新。 case不会导致这样的更新。

例如,以下适用于 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

关于Idris : Is it possible to rewrite all functions using "with" to use "case" instead of "with" ? 如果不是,你能举个反例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35610366/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com