How would one count the number of times a data type was passed into a function and a total of the values? I am new to FP and not sure if this is permitted by mutability laws or referential transparency. The context is working with stacks and trying to work out if you passed in a series of instructions to the stack you could work out the frequency particular instruction was passed in and the total value of all those type, as a sort of counter... I have searched around to no avail and starting to think my approach may be fundamentally flawed so any advice would be appreciated, but i thought i would put it out there as i'm interested to know, i was working along the lines of;
> data Value > = Numeric Int > | Logical Bool > deriving (Eq, Show, Read) ... > data Instruction > = Push Value > | Pop > | Fetch Int > | Store Int ... > step inst c= > case (inst) of > (Push, stack) -> (c', x : stack) > (Pop, _ : stack) -> (c', stack) > where > c = c' + 1 ...
Push
constructor appears without a parameter in the definition ofstep
). – Luis Casillas