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:
Anonymous2012-03-09 19:03
I LOVE YOU!I LOVE YOUR POST!I READ IT FIVE TIMES!KEEP POSTING!
Name:
Anonymous2012-03-09 19:03
also: first class environments/contexts
Name:
Anonymous2012-03-09 19:56
I'm an American Nigger, and I'm a FIRST CLASS CITIZEN
>>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:
Anonymous2012-03-09 21:05
javascript
Name:
Anonymous2012-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:
Anonymous2012-03-09 21:22
Python.
Name:
Anonymous2012-03-09 21:26
First class dubs
Name:
Anonymous2012-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:
Anonymous2012-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:
Anonymous2012-03-10 3:49
>>12
M'eh. Real languages do all that at compile time.
Name:
Anonymous2012-03-10 5:59
Yeah first class types would be hot as cats piss on a hit tin roof
>>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.
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:
Anonymous2012-03-10 17:45
>>25
What do you want that's different from typeclasses anyway? Seriously, give me a use-case.
Name:
Anonymous2012-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
>>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:
Anonymous2012-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.
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:
Anonymous2012-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:
Anonymous2012-03-10 22:25
haskell, using Typeable, sorta has first class types
Name:
Anonymous2012-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:
Anonymous2012-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:
Anonymous2012-03-16 8:38
OH MY GOD PEANO NUMBERS, WE GOT PEANO NUMBERS OVER HERE
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!!!!