SML problem with use of binary trees and pattern matching : ml
This is a discussion on SML problem with use of binary trees and pattern matching within the ml forums in Programming Languages category; Hi, I have got a problem with the use of pattern matching and binary trees in SML. When I type in: datatype 'a btree = emptybt | build of 'a * 'a btree * 'a btree; and then define a function with a 'a btree as argument using pattern matching: fun isemptybtree emptybt = true | isemptybtree (build (v, l, r)) = false; there is no problem. However, in my programming course we have to use a binary tree module: signature bintree_s = sig type 'a bintree exception emptytree val emptybt: 'a bintree val build: 'a * 'a bintree * ...
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| I have got a problem with the use of pattern matching and binary trees in SML. When I type in: datatype 'a btree = emptybt | build of 'a * 'a btree * 'a btree; and then define a function with a 'a btree as argument using pattern matching: fun isemptybtree emptybt = true | isemptybtree (build (v, l, r)) = false; there is no problem. However, in my programming course we have to use a binary tree module: signature bintree_s = sig type 'a bintree exception emptytree val emptybt: 'a bintree val build: 'a * 'a bintree * 'a bintree -> 'a bintree val root: 'a bintree -> 'a val left: 'a bintree -> 'a bintree val right: 'a bintree -> 'a bintree val isemptybt: 'a bintree -> bool end structure BINTREE : bintree_s = struct datatype 'a bintree = emptybt | build of 'a * 'a bintree * 'a bintree exception emptytree fun root emptybt = raise emptytree | root (build (x, l, r)) = x fun left emptybt = raise emptytree | left (build (x, l, r)) = l fun right emptybt = raise emptytree | right (build (x, l, r)) = r fun isemptybt emptybt = true | isemptybt _ = false end I load that module, open it, and then I want to define the same function as above: fun isemptybtree emptybt = true | isemptybtree (build (v, l, r)) = false; I get the following error: Error: non-constructor applied to argument in pattern: build What can I do about that and how can I use pattern matching with this module? I'd be glad to get some hints. Valentin |
|
#2
| |||
| |||
| Change the signature to have the entire definition of the datatype. Eliminate the val lines for 'emptybt' and 'build'. |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem pattern matching on a field | usenet | awk | 4 | 09-24-2007 03:17 PM |
| Re: Creating pattern for matching problem | usenet | labview | 0 | 09-11-2007 05:10 AM |
| matching pattern problem with decimal numbers | usenet | awk | 3 | 07-21-2006 04:53 PM |
| pattern matching dynamic strings w/ regex ending in $ problem | usenet | Perl | 4 | 05-07-2005 07:24 AM |
| Pattern matching problem, ocaml | usenet | ml | 4 | 01-31-2005 01:00 PM |
All times are GMT -5. The time now is 04:31 PM.


