How to translate logical notation to Haskell syntax

后端 未结 4 965
天命终不由人
天命终不由人 2021-01-25 13:22

I\'ve recently picked up Haskell at uni and I\'m working my way through a set of exercises, here\'s a snippet of one that I can\'t make sense of:

\"Consider the followin

4条回答
  •  被撕碎了的回忆
    2021-01-25 14:14

    If it is just a exercise about modeling data (without code) the answer consist of adding constructor names to your grammar (and changing literal number to names). Something like

    data Num = Zero | One | Two | Three | Four | Five 
             | Six | Seven | Eight | Nine
    data Int = Single Num | Multiple Num Int
    data Exp = ExpInt Int | ExpMinus Exp Exp | ExpMul Exp Exp
             | ExpMul Exp Exp
    

    From that, you can write all sort of code, to parse and evaluate expressions.

提交回复
热议问题