[plt-scheme] Re: The perfect teaching language--Is this too much to ask for?

From: Prabhakar Ragde (plragde at uwaterloo.ca)
Date: Sun Jun 14 19:26:30 EDT 2009

wooks writes:

> My FP course was taught in Miranda supposedly because Miranda is a
> teaching language. The incomprehensible type error problem can be
> mitigated by defining abstract data types.

I think the problem shows up even before that. In Haskell, which is 
pretty much identical to Miranda for this program:

import System.IO

len [] = 0
len [x:xs] = 1 + len xs

main = print (len "test")

Here's the error message I get from GHC, pointing at the second `len' line:

>     Occurs check: cannot construct the infinite type: t = [t]
>       Expected type: [t] -> t1
>       Inferred type: [[t]] -> t2
>     In the second argument of `(+)', namely `len xs'
>     In the expression: 1 + len xs

Now, if you define your own List type (which is Cons or Empty), maybe 
you won't make this mistake in the first place. But I bet one can 
construct examples with naive mistakes that result in similar messages. 
(Does Helium do better on this program? Maybe someone with it installed 
can check?)

Earthbound static type systems (C-style) make abstraction difficult, and 
I don't think they really assist beginners in finding their mistakes 
(though I may be biased by GCC's habit of making assumptions). More 
sophisticated type systems (permitting polymorphism at the very least) 
need to be understood, which is definitely not easy for a beginner.

I think there is scope for some optional assistance with types -- the 
define-type and type-case macros used in PLAI and EOPL, for instance, or 
a macro for function definition that puts in primitive type checks on 
arguments and results. But I think that a first course should not go 
much beyond these. I have taught first year with static types and 
dynamic types, and dynamic types are much easier. --PR

Posted on the users mailing list.