Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

First-class everything

Name: Anonymous 2012-03-09 18:57

Do any programming languages have everything as first-class citizens? This includes not only functions, but types, classes, etc. too. Having everything first-class can be a flexible and non-kludgy alternative to generics/templates.

Name: Anonymous 2012-03-10 19:25

>>27
Heh, I guess adding dimensions to a type resulting in a flat type is a valid want. If you try that with OCaml or whatever you won't end up with a flat type. But you can be a smartass and the compiler won't care as long as you're autistic consistent about it:

let f x y =
    match x with
    | true -> `oranges 10
    | false -> `apples (y::[y]);;
val f : bool -> 'a -> [> `apples of 'a list | `oranges of int ] = <fun>

Printing that will require something to accept the typeclass you've produced and do the right thing (this has nothing to do with your call to 'weird' though.) If you use a tagged type for whatever 'a turns out to be you could print the list trivially though.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List