# Haskell's syntax

**Johannes Waldmann
**
joe@informatik.uni-leipzig.de

*Tue, 22 Apr 2003 16:06:15 +0200 (MET DST)*

>* (3) Types and expressions look very much alike. Say we have:
*>* data Tree a = Bin (Tree a) a (Tree a) | Nil.
*
I encourage my students to always use named record notation
data Tree a = Bin { left :: Tree a, ... }
>* Around half (!) of the students now write (on a written test):
*>* size (Bin (Tree left) x (Tree right)) = ...
*
sure they had this in their mind:
size (Bin ( left :: Tree a ) ( x :: a ) ( right :: Tree a )) = ...
(i. e. they wanted to specify the types of formal parameters
at the most natural place - at their first appearance in the text)
I think the following is conceptually cleaner
size ( t @ Bin { } ) =
let l = left t
r = right t
in size l + 1 + size r
(it separates matching and binding)
altough the first line looks rather cryptic.
NB: I wouldn't mind the language enforcing the students ( and me ) to write
size ( t @ Bin { } :: Tree a ) =
let l :: Tree a = left t
r :: Tree a = right t
in size l + 1 + size r
Best regards,
--
-- Johannes Waldmann ---- http://www.informatik.uni-leipzig.de/~joe/ --
-- joe@informatik.uni-leipzig.de -- phone/fax (+49) 341 9732 204/207 --