nsc010
nsc010

Reputation: 385

What would i type in GHCI to test this code

I'm new to haskell and came across some code on wikipedia

data Tree a = Tip | Node a (Tree a) (Tree a) deriving (Show,Eq)

height Tip = 0
height (Node _ xl xr) = 1 + max (height xl) (height xr)

source: http://www.csse.monash.edu.au/~lloyd/tildeFP/Haskell/1998/Tree/

I was wondering what would I have to type in GHCI to test this code, once i run the code from a file

Upvotes: 0

Views: 152

Answers (1)

Chris Taylor
Chris Taylor

Reputation: 47382

You can try the following. If the code in your question is in a file "Main.hs" then do

$ ghci Main.hs
>> height Tip
0
>> height (Node "a" Tip Tip)
1
>> height (Node "a" Tip (Node "b" Tip Tip))
2

&c.

Upvotes: 1

Related Questions