Functional Programming
14. Haskell Tips




14.1 Conversion

Helpful Hint: To convert strings into numbers, do this: *Main> read "12.3"::Float
12.3
*Main> read "-42"::Int
-42


14.2 Modules

Haskell has a module feature which lets you bundle up types and operations. code/Haskell/ExpTrees/treemodule.hs

    module Tree ( Tree(Leaf,Branch), fringe ) where
     
    data Tree a = Leaf a | Branch ( Tree a ) ( Tree a )  deriving (Eq, Show)
     
    fringe :: Tree a -> [a]
    fringe ( Leaf x )            = [x]
    fringe ( Branch left right ) = fringe left ++ fringe right

14. Haskell Tips
Notes on Functional Programming / Version 2.10 2014-02-24