2020年10月27 平凡的变换 that makes sense¶
Build FsLexYacc时不要开VSCode
idea就是编译到F#
好处:
- 编译器能处理source location map,语法
# 17 filename.txt
- fsharp编译速度比较快
- FSLexYacc
- 平凡的AST变换,非常完备的编译器
Delim Cont¶
let k = fun ``delim cont`` -> (x + ``delim cont``)
in expr
from
reset { x + shift k expr}
Extensible Records(Type Definition)¶
type Rec<'a> = {
a : 'a;
}
type Rec<'a> = ``Rec _`` of 'a
with
member this.``get a`` =
let (F(a)) = this in a
member this.``update a`` (f : 'a -> 'a_)=
let (F(a)) = this in
F(f a)
interface ``Prop a``<Rec<'a>, 'a> with
member this.``get a`` = this.``get a``
member this.``update a`` f = this.``update a`` f
end
where
type ``Prop a``<'a, 'b> = interface
abstract member ``get a`` : 'b
abstract member ``update a``: ('b -> 'b) -> 'a
end
Extensible Records(Type Usage)¶
def get_fff: forall 'a 'b when {'a.fff : 'b} . 'a -> 'b =
|x| x.fff
to
let get_fff<'a, 'b when 'a : ``Prop fff``<'a, 'b>> : 'a -> 'b =
(fun x -> x.fff)
Nested Data Update¶
x.a.b.c by |x| x + 1
to
x.``update a`` (fun a ->
a.``update b`` (fun b ->
b.``update c`` (fun x -> x + 1)
))
x.a.b.{
c by f1;
d by f2;
}
to
x.``update a`` (fun a ->
a.``update b`` (fun b ->
b
|> (fun b -> b.``update c`` f1)
|> (fun b -> b.``update d`` f2)
))