Is it possible to emulate a function using your own data type?

前端 未结 3 1728
南方客
南方客 2021-01-11 16:37

Is it possible to emulate a function with your own data type with some GHC extension? What I want to do is e.g.

(imaginary syntax)

data MyFunc = MyFu         


        
3条回答
  •  独厮守ぢ
    2021-01-11 17:32

    You can't directly overload function call syntax, no.

    You can make your own custom arrow type --- see Control.Arrow. You can then invoke your "functions" using arrow notation (you will need to include {-# LANGUAGE Arrows #-} at the top of your source file). Whether this is good enough for you depends on the needs of your DSL.

提交回复
热议问题