[Haskell-cafe] String to binary tree

Sebastian Sylvan sylvan at student.chalmers.se
Tue May 30 16:53:37 EDT 2006


On 5/30/06, Thorkil Naur <naur at post11.tele.dk> wrote:
> Hello,
>
> Both my Hugs and my GHCi report a type error when presented with this. A
> possible repaired version looks like this:
>
>   calc :: String -> Float
>   calc = g . foldl f [] . words
>     where
>       f (x:y:zs) "+" = y+x:zs
>       f (x:y:zs) "-" = y-x:zs
>       f (x:y:zs) "*" = y*x:zs
>       f (x:y:zs) "/" = y/x:zs
>       f xs y = read y : xs
>       g [r] = r
>
> Not as small, but still quite nice.
>

..or you could just have it return [Float], maybe that's the intention
(you could do several computations). Or throw in a "head" in there
instead of defining a new function.

/S
-- 
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list