Statically Typed Metaprogramming?

后端 未结 5 2221
自闭症患者
自闭症患者 2021-02-18 15:43

I\'ve been thinking about what I would miss in porting some Python code to a statically typed language such as F# or Scala; the libraries can be substituted, the conciseness is

5条回答
  •  再見小時候
    2021-02-18 16:20

    Without knowing why you're doing this, it's difficult to know whether this kind of approach is the right one in Scala or F#. But ignoring that for now, it's certainly possible to achieve in Scala, at least, although not at the language level.

    A compiler plugin gives you access to the tree and allows you to perform all kinds of manipulation of that tree, all fully typechecked.

    There are some issues with generating synthetic methods in Scala compiler plugins - it's difficult for me to know whether that will be a problem for you.

    It is possible to work around this by creating a compiler plugin that generates source code which is then compiled in a separate pass. This is how ScalaMock works, for instance.

提交回复
热议问题