Author | Message |
---|---|
jungsoolim
Posts: 38
|
Posted 20:24 Feb 16, 2019 |
I started with creating a stack as this: data IntString = I Integer | S String | C Char deriving Show
However, Professor Abbott suggests to use a list in place of stack as ghci> let l = List This is much simpler and easier to work with.
|
rabbott
Posts: 1649
|
Posted 20:40 Feb 16, 2019 |
I don't think you have to declare a List data type. Just use a list directly as in your example. (You can also get along without the parentheses.)
Last edited by rabbott at
20:40 Feb 16, 2019.
|
rabbott
Posts: 1649
|
Posted 20:48 Feb 16, 2019 |
For the particular problem this week, though, since there only character is '+' and the only string is 'fib' just make them constructors. > data FibElement = I Integer | Fib | Plus deriving Show > x = [Plus, Fib, I 5, Fib, I 4] > x > :type x |
jungsoolim
Posts: 38
|
Posted 20:50 Feb 16, 2019 |
Thanks! |
rabbott
Posts: 1649
|
Posted 20:56 Feb 16, 2019 |
Perhaps even better, since you will never be applying Fib to an unknown argument (that is, whenever you put Fib into a list, you know at that time what its argument is), you might define:
> data FibElement = I Integer | Fib Integer | Plus deriving Show Last edited by rabbott at
21:00 Feb 16, 2019.
|