File: TreeADT.lhs

package info (click to toggle)
haskell98-tutorial 200006-2-1.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 864 kB
  • ctags: 59
  • sloc: haskell: 2,125; makefile: 66; sh: 9
file content (15 lines) | stat: -rw-r--r-- 437 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Since TreeADT does not import Tree it can use the name Tree without
any conflict.  Each module has its own separate namespace.

> module TreeADT (Tree, leaf, branch, cell, left,
>                right, isLeaf) where

> data Tree a = Leaf a | Branch (Tree a) (Tree a)    deriving Show

> leaf = Leaf
> branch = Branch
> cell (Leaf a) = a
> left (Branch l r) = l
> right (Branch l r) = r
> isLeaf (Leaf _) = True
> isLeaf _        = False