How to Do the function

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

count :: Fun → Float

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

count Finish = 


which constitutes the end of a sequence which is 0 maybe

1 Like

Ok, so

count Finish = 0

Do you have any grasp or recursion? Can you guess what

count (Num i f) = 

could be?

count (Num i f ) = i : count f

@f-a Any help please

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.