Monday 29 June 2015

The Fifth Problem (2)

So now I will want to merge the list of operations into the list of numbers.  I did a merge function already recently, it went like this:-

mergeops :: String -> String -> String
mergeops ns [] = ns
mergeops [] os = os
mergeops (n:ns) (o:os) = n : o : mergeops ns os

For example two digits then plus then two digits then minus then two digits...

*Main Data.Char> mergeops "123456789" "__+__-__"
"1_2_3+4_5_6-7_8_9"

Ah yes I will want to filter out the "nothing" operation characters, say like this:-

*Main Data.Char> filter (\c -> c /= '_') it
"123+456-789"

The bit in the brackets is a lambda, the function taking c and returning a boolean true if c is not equal to the underline character.

And it is the Haskell shell's way of giving you the result of the previous expression you just evaluated.

No comments:

Post a Comment