Don*_*art 31 compiler-construction haskell agda
在Agda邮件列表中,Conor McBride问道:
有没有办法像假定的那样掌握行动
Run Code Online (Sandbox Code Playgroud)trustFromJust :: Maybe x -> x
如果没有任何东西,它实际上并没有检查Just and Goes Wrong(在Milner的意义上)?
Agda可能会证明Maybe a == Just1 a,并且可以消除sum类型的中间构造函数.
我可以想到使用unsafeCoerce#或unpackClosure#的方法,但其他人是否有想法?
import GHC.Prim
trustFromJust :: Maybe x -> x
trustFromJust x = y
where Just1 y = unsafeCoerce# x
data Just1 a = Just1 a
Run Code Online (Sandbox Code Playgroud)
虽然这个段错误(单个构造函数类型可以避免一些闭包开销).核心看起来不错:
main2 =
case (Data.Maybe.Just @ Type.Integer main3)
`cast`
(CoUnsafe
(Data.Maybe.Maybe Type.Integer)
(Just1 Type.Integer)
:: Data.Maybe.Maybe Type.Integer
~
Just1 Type.Integer)
of _ { Just1 y_aeb ->
$wshowsPrec 0 y_aeb ([] @ Char)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1552 次 |
最近记录: |