An entity in a programming language is called first-class if it can be constructed and manipulated at runtime.
Questions tagged [first-class]
36 questions
32
votes
7 answers
What are first-class objects in Java and C#?
When I started OO programming many years ago I gained the impression that variables (if that is the right word) were either "primitives" (int, double, etc.) or first-class objects (String, JPane, etc.). This is reinforced by a recent answer on…

peter.murray.rust
- 37,407
- 44
- 153
- 217
14
votes
3 answers
Are primitive types different in Java and C#?
I am manually converting code from Java to C# and struggling with (what I call) primitive types (see, e.g. Do autoboxing and unboxing behave differently in Java and C#). From the answers I understand that double (C#) and Double (C#) are equivalent…

peter.murray.rust
- 37,407
- 44
- 153
- 217
9
votes
1 answer
First-Class Citizen
The definition of first-class citizen found in the wiki article says:
An object is first-class when it
can be stored in variables and data structures
can be passed as a parameter to a subroutine
can be returned as the result of a subroutine
can…

nawK
- 693
- 1
- 7
- 13
8
votes
3 answers
Are scala case patterns first class?
Is it possible to pass case patterns as parameters to other functions? Something like this:
def foo(pattern: someMagicType) {
x match {
pattern => println("match")
}
}
def bar() {
foo(case List(a, b, c))
}

fredoverflow
- 256,549
- 94
- 388
- 662
4
votes
4 answers
In what sense are types in Common Lisp first-class?
Peter Norvig famously claimed that many OOP design patterns are trivial or redundant in Lisp. Slide #10 here claims that first-class types replace many of them.
In what sense are types first-class in Common Lisp? For reference, Structure and…

J. Mini
- 1,868
- 1
- 9
- 38
4
votes
3 answers
What are the benefits of types being first-class objects?
Does anybody here have good examples where types as first-class objects come in hand?
I guess it helps to straightforwardly implement some math concepts, indeed that is the kind of examples I'm looking for.
UPD To clarify the question, what can be…

Yrogirg
- 2,301
- 3
- 22
- 33
4
votes
3 answers
First class generic function in swift?
Swift has first class functions that can be passed as arguments.
func a() {
}
func b(x: ()) {
}
// Pass a to b…
b(a)
Swift has generic functions.
func generic(x: T) {
}
But, does Swift let me pass a generic function as an argument to another…

Benjohn
- 13,228
- 9
- 65
- 127
4
votes
4 answers
First class patterns in Erlang? (Alternatives)
Is there a way to create first-class-like patterns in Erlang? I need to be able to create and pass patterns as args to other functions but I know patterns are not first class in Erlang. I also looked at Elixir but it doesn't seem to offer anything…

Stratus3D
- 4,648
- 4
- 35
- 67
4
votes
3 answers
Can First-class functions in Scala be a concern for allocating a large PermGen Space in JVM?
Regarding first-class functions in Scala, it is written in the book Programming by Scala:
A function literal is compiled into a
class that when instantiated at
run-time is a function value.
When there will be many first-class functions used in…

Monis Iqbal
- 1,987
- 7
- 26
- 42
4
votes
2 answers
First-class patterns in Erlang?
Are there any support for first-class patterns in Erlang?
f(SomeMagicPattern) ->
receive
SomeMagicPattern -> ok
end.
If the answer is no (support), do you know any other approach for achieving this? For example, using macros?

Xiao Jia
- 4,169
- 2
- 29
- 47
3
votes
3 answers
Store classes in a Map so that they can be instantiated
I want to be able to create instances of classes, based on HashMap entries.
E.g. this is what I'd try writing off the top of my head:
public class One implements Interface {
public void sayName() {
System.out.println("One");
}
}
public…

theonlygusti
- 11,032
- 11
- 64
- 119
3
votes
1 answer
How can I implement a typeOf function?
Since types are first-class in Idris, it seems like I should be able to write a typeOf function that returns the type of its argument:
typeOf : a => a -> Type
typeOf x = a
However, when I attempt to call this function, I get what looks like an…

Sam Estep
- 12,974
- 2
- 37
- 75
3
votes
1 answer
Instantiate a module in OCaml dynamically
I have several modules implementing the same interface. I want to load only one of this module depending on one argument given on the command line.
I was thinking to use first-class module but the problem is that I want to execute some functions…

Saroupille
- 609
- 8
- 14
3
votes
0 answers
Abstract Factory and classes as first class objects
A theoretical question. I'm reading Gof's Design Patterns, section Abstract Factory. The book mentions the possibility of implementing this pattern like a Prototype or, if the language permits it, with a Prototype which stores classes instead of…

Pippo
- 1,543
- 3
- 21
- 40
2
votes
2 answers
F#: How to Access a Dotnet Object's Method's Specific Overload as a First Class-object
I can do this (F# FSI):
let o = Object()
let m = o.GetHashCode;; //[1]
val o : Object
val m : (unit -> int)
which makes method GetHashCode accessible and callable as a first-class function in binding m:
m ();;
val it : int = 12345678
How would I…

7enderhead
- 71
- 4