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

Pages: 1-

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-09 19:03

I LOVE YOU! I LOVE YOUR POST! I READ IT FIVE TIMES! KEEP POSTING!

Name: Anonymous 2012-03-09 19:03

also: first class environments/contexts

Name: Anonymous 2012-03-09 19:56

I'm an American Nigger, and I'm a FIRST CLASS CITIZEN

Name: Anonymous 2012-03-09 20:01

>>1
First-class trolling

>>4
Stop the racism, please.

Name: Anonymous 2012-03-09 20:58

>>5 he's black, he's allow to say the n-word.

Name: Anonymous 2012-03-09 20:59

>>5 he's black, he's allow to say the n-word. And how can a black man be racist? Only whites are racist.

Name: Anonymous 2012-03-09 21:05

javascript

Name: Anonymous 2012-03-09 21:16

>>8
you can pass a "this" to a function, but that doesn't change the context of where its code looks up names

Name: Anonymous 2012-03-09 21:22

Python.

Name: Anonymous 2012-03-09 21:26

First class dubs

Name: Anonymous 2012-03-09 22:08

I was actually going to try to implement first class types in a programming language. You could implement a function which takes arbitrary arguments (including other types) and returns a type, created at run time.

Name: Anonymous 2012-03-09 22:50

>>5 he's a first class nigger, he's allow say n-word

STOP BEING SO FUKKING NGGER MATURE RACIST NIGGER NIGGER AFRICAN BLACK NIGGER AMERICANO FUCKING NIGGER NIGGER MATURE

Name: Anonymous 2012-03-10 3:49

>>12
M'eh. Real languages do all that at compile time.

Name: Anonymous 2012-03-10 5:59

Yeah first class types would be hot as cats piss on a hit tin roof

Name: Anonymous 2012-03-10 7:16

first class macros

Name: Anonymous 2012-03-10 9:56

What about first-class first classes?

Name: Anonymous 2012-03-10 15:11

>>15
Have you guys never heard of algebraic data types or type-polymorphism?

>>17
You want prototypes. Otherwise you end up with something like Ruby's object model.

Name: Anonymous 2012-03-10 15:51

>>12
Easily done in C.

Name: Anonymous 2012-03-10 15:55

Perl 6 has

Name: Anonymous 2012-03-10 16:21

>>20
Perl 6 is cheating.

Name: Anonymous 2012-03-10 16:31

>>20
First class flow control is pretty amazing.

Name: Anonymous 2012-03-10 16:32

First class integers

Name: Anonymous 2012-03-10 16:47

>>19
true, but not necessarily syntacically convenient, and support from the compiler for the same sort of capabilities could (in some cases) be more type safe.

Name: >>24 2012-03-10 17:09

nevermind about the type safety. With that kind of generality you kind of have to give up on that. But the syntax would be nice I guess. I could see it being similar to pattern matching syntax of ocaml and friends, where matching a variable with a parameterized type would allow you to extract the parameters used in the type.

Name: Anonymous 2012-03-10 17:45

>>25
What do you want that's different from typeclasses anyway? Seriously, give me a use-case.

Name: Anonymous 2012-03-10 18:21

>>26
It's probably difficult to think of an actual use case that would be useful, but an example:


array : type -> int -> type
arr = instance (array int 4)
arr2D = instance (array (array int 4) int 4)

array2D_t : type -> int -> int -> type
array2D_t item_t x_dim y_dim =
  array (array item_t x_dim) y_dim

arr2D = instance (array2D_t int 20 20)


weird : int -> type
weird n =
  if (n % 2) == 0 then
    int
  else
    array int 23
  end

test n =
  let what_now_bitch instance (weird n)
  in print what_now_bitch

Name: Anonymous 2012-03-10 18:27

>>27
Agda

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.

Name: Anonymous 2012-03-10 19:54

>>29
I think the weird function is actually implementable in a more regular scheme. Just take the set of all types that weird could possibly return, and make a wrapper type for these types. Then provide a function that returns an instance of one of the sub types.


abstract class weird {
 ...
}

class weird_int inherits weird {
  ...
}

class weird_int_array inherits weird {
  ...
}

weird make_weird(int n) {
  if(n % 2 == 0) {
    return new weird_int();
  } else {
    return new weird_int_array();
  }
}


The only loss is that one could potentially do something like the following using the >>27 syntax:


arr = array (weird n) 33


You could represent this as:


weird[] arr = new weird[33];


and only put one type of weird in it, but you couldn't have the compiler enforce you only putting one sub type of weird in it.

Name: >>30 2012-03-10 20:03

but then again, how should the compiler know that weird 2 is the same type as weird 4? And that an object of type weird 33 can be inserted into an array of type array (weird 103) n?

Name: Anonymous 2012-03-10 20:37

>>24,25
You can make it more type safe than regular C, since now you actually have control of the structure and may hide it from the user. You just define "type" in a different way, so the C type might be whatever, but you use some other mechanism to look the type up.

The other posts you made were just inane bullshit so I didn't bother to read them thoroughly.

Name: Anonymous 2012-03-10 22:25

haskell, using Typeable, sorta has first class types

Name: Anonymous 2012-03-16 3:25

>>6
he's black, he's allow to say the n-word.
this is the kind of american idiocy that makes my blood boil every time

Name: Anonymous 2012-03-16 8:11

CAN YOUR TOY-LANGUAGE DO THIS:


data ℕ : Set where
    zero : ℕ
    succ : ℕ → ℕ

_+_ : ℕ → ℕ → ℕ
zero     + n = n
(succ m) + n = succ (m + n)

data List (A : Set) : ℕ → Set where
  []   :                           List A zero
  _::_ : {n : ℕ} → A  → List A n → List A (succ n)

head : {A : Set} {n : ℕ} → List A (succ n) → A
head (x :: _) = x

tail : {A : Set} {n : ℕ} → List A (succ n) → List A n
tail (_ :: xs) = xs

_++_ : {A : Set} {n m : ℕ} → List A n → List A m → List A (n + m)
[]        ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)

didn't thought so

Name: Anonymous 2012-03-16 8:38

OH MY GOD PEANO NUMBERS, WE GOT PEANO NUMBERS OVER HERE

Name: Anonymous 2012-03-16 9:05

You're now watching two strangers discuss your question!
Question to discuss
:
Have you read your ``Structure and Interpretation of Computer Programs'' book today?

Stranger 2: Have you read the bible and praise the lord today?
Stranger 1: oh, so that's what SICP meant... no i haven't
Stranger 2: JESUS!!!!

Stranger 2 has disconnected

Name: Anonymous 2012-03-16 9:40


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