[Haskell-cafe] Re: Data constructors versus types

Achim Schneider barsoap at web.de
Wed Jan 16 18:31:38 EST 2008


Peter Verswyvelen <bf3 at telenet.be> wrote:

> Thank you for explaining.
> 
> I was wondering if the same syntax could be used somehow (not in
> Haskell, in some theoretical language), I mean use an annotation to
> tell the compiler that a "type-tag" should be determined at compile
> time and not at runtime, otherwise -> error
> 
> So eg
> 
> // Runtime tag, aka data constructor
> foo (Int n) = ...
> 
> // Compile tag, aka type
> foo (>Int< n) = ...
> 
> Might not make any sense...
> 
ghc --ddump-simpl and assure that your values get unboxed...

> You're talking about O(big)... But wasn't the C language in some way
> succesful because on the hardware at that time other much nicer
> languages (e.g. LISP) were just way too slow? Or was this just O(n)
> times slower? 
> 
Compiler technology also wasn't as advanced as now, Stalin can't
compile even small programs under say 5 minutes... compare this to e.g.
TurboPascal, which afair uses three passes: Parsing, Error Reporting,
Code Generation, it was similar with C compilers back then.

Lisp was fast on lisp machines, where it is the same as what C is to
Neumann-Architectures: An assembler.

I'm not at all sure about the specific O's involved, but I guess it's
quite easy to get to NP-complete if you want to do really much without
much information.


> IMHO: Shouldn't concepts that are conceptually the same (in this case,
> "giving meaning/adding constraints to bits of data" ) at runtime and
> compile time look very similar in the language? Most languages require
> completely different syntax and code when you want something to be
> lazy versus strict. Haskell doesn't, you can just add an annotation
> if you want it to be strict, no much rewriting is required. However,
> if I want to change a runtime data constructor definition (and code)
> into a compiletime type, then I can rewrite all of my code basically.
> That is not the case in SCHEME as far as I understand it.
> 
Scheme knows no types but the builtins like INT or PAIR or LIST or
SYMBOL and so on. Even if you distinguish say

('complex 1 2)
from
('vec3 1 2 3)

, the compiler in general won't stop you from passing these things into
the wrong functions. It doesn't even know that a function is passed a
"LIST (QUOTEDSYMBOL INT INT)" or "LIST (QUOTEDSYMBOL INT INT INT)", it
just sees a pair, in both cases.

Lisp is actually not really meant to be compiled, but interpreted. The
nice thing is that it doesn't need more than a handful of primitives, a
list parser and heap manager/garbage collector and evaluator, which all
can be implemented in under 1000 lines of C. Things get more involved
with get/cc, but then how many C programmers ever heard of setjmp...

on top of my head, one set of possible primitives is

quote lambda set! succ pred cond.

you can then start by defining define by

(set! 'define (lambda (sym f) (set! sym f)))

There's the wizard book and Graham's Ansi Common Lisp if you're
interested in how cheap lisp actually is.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 



More information about the Haskell-Cafe mailing list