Hello, I have to need to write a function which counts each letter from the string and returns the number of characters as the float number of each of the characters is 0.3 and adds it to the time.
data Fun =
Word String Fun
| Num Int Fun
| Finish
deriving Show
this is my function which I define. I do not know what to do next. I am stuck on it I need to first count the Word each character is 0.3 and then add it to the int and return it as the float number. Any kind of suggestion. or help
Hello Gural,
you need a function with type :: Fun -> Float, your best bet is to go through all the data constructors. Let’s start from the simplest one. What would
You said you wanted the result to be Float, but now you are using the : operator which constructs a list. Instead I think you want to use fromIntegral to convert the Int to a Float and then you can use + to sum that float to the result of the recursive call count f, so count (Num i f) = fromIntegral i + count f.