Equivalent of python eval in Haskell

后端 未结 5 570
闹比i
闹比i 2021-02-05 20:21

There is function in python called eval that takes string input and evaluates it.

>>> x = 1
>>> print eval(\'x+1\')
2
>>>         


        
5条回答
  •  一生所求
    2021-02-05 20:41

    There is no 'eval' built into the language, though Template Haskell allows compile time evaluation.

    For runtime 'eval' -- i.e. runtime metaprogramming -- there are a number of packages on Hackage that essentially import GHC or GHCi, including the old hs-plugins package, and the hint package.

提交回复
热议问题