File: part23.lhs

package info (click to toggle)
haskell98-tutorial 200006-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 624 kB
  • ctags: 11
  • sloc: haskell: 2,125; makefile: 80; sh: 13
file content (27 lines) | stat: -rw-r--r-- 529 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Gentle Introduction to Haskell 98, Online Supplement 
Part 23
Covers Sections 11.2, 11.3

11.2 Abstract Data Types

> module Part23() where

> import TreeADT

See TreeADT.lhs

Since the constructors for type Tree are hidden, pattern matching
cannot be used.

> fringe :: Tree a -> [a]
> fringe x = if isLeaf x then [cell x]
>                        else fringe (left x) ++ fringe (right x)

> e1 :: [Int]
> e1 = fringe (branch (branch (leaf 3) (leaf 2)) (leaf 1))

11.3 More Features

No examples (yet).

Continued in part24.lhs