Skip to main content
31 events
when toggle format what by license comment
S Jun 4, 2023 at 7:09 vote accept Jörg W Mittag
Jun 4, 2023 at 3:07 answer added davidalayachew timeline score: 6
Jun 1, 2020 at 16:03 history edited Jörg W Mittag CC BY-SA 4.0
deleted 1 character in body
Aug 9, 2019 at 2:31 comment added aoeu256 C# isn't real OOP... Real OOP(Talking about Smalltalk/Alan Kay) has stuff like getattr, method_missing, metaobject protocols, JavaScript's prototypes, interactive development, and uses clojures/blocks instead of ravioli objects...
Oct 18, 2015 at 15:01 answer added jameshfisher timeline score: 4
Oct 17, 2015 at 20:53 history protected gnat
Jun 8, 2014 at 15:02 comment added Display Name >"Solve problems using OOP. Don't try using any other paradigm." What if I hate OOP? codegolf.stackexchange.com/a/24887/6485
Feb 7, 2014 at 15:57 answer added Joey Adams timeline score: 17
Nov 13, 2012 at 6:56 comment added Giorgio @Jörg W Mittag: Thanks for the hints. As far as I understand, anonymous inner classes in Java are a generalization of lambdas, using a different (more verbose syntax). I will try it out, maybe it can be encapsulated enough to be usable.
Nov 13, 2012 at 0:49 comment added Jörg W Mittag @Giorgio: Java doesn't support lazy evaluation natively, therefore you need to "fake" it. The common way to fake lazy evaluation is with lambdas. Of course, Java doesn't have those, either, so you need to "fake" those as well, using anonymous inner classes implementing Single-Abstract-Method Interfaces.
Nov 12, 2012 at 20:31 comment added Giorgio Very interesting question. I tried to code lists in Java following the suggestions of James and Petr. Now I wanted to try and implement streams (lists in which the tail is evaluated lazily, similar to streams in Scala). Is there a way to do this in Java? Does it make sense to post this as a separate question?
Oct 25, 2012 at 12:52 review Close votes
Oct 25, 2012 at 16:17
Sep 7, 2012 at 17:53 comment added SK-logic @Euphoric, paradigm, schmaradigm, who cares? ADTs are orthogonal to the functional programming (or OOP or whatever else). Encoding an AST of any language is quite a pain without decent ADTs support, and compiling that language is a pain without another paradigm-agnostic feature, pattern matching.
Sep 6, 2012 at 23:49 vote accept Jörg W Mittag
S Jun 4, 2023 at 7:09
Sep 6, 2012 at 22:34 answer added James Iry timeline score: 52
Aug 8, 2012 at 16:31 comment added Peter Taylor Java sort-of has polymorphic values in some cases because its generics are implemented by erasure. You could have a single instance of Empty which is cast by an accessor method to Empty<T>. You'll get a couple of warnings unless you suppress them, but I believe this is actually used in the standard library for things like Collections.emptySet().
Aug 8, 2012 at 16:23 comment added Jörg W Mittag @TikhonJelvis: Another way to look at it: in Haskell, the empty list is a polymorphic value, as you point out. AFAIK, neither C# nor Java allow polymorphic values, so you simply can't have an empty list of type Empty<T>, it has to be of some concrete type Empty<Something>. Since you want that type to be substitutable for every empty list, it needs to be a subtype of all lists, which can be achieved if Something is a subtype of all types, i.e. a bottom type.
Aug 8, 2012 at 14:14 comment added Jörg W Mittag @Euphoric: some domains are easy to model with objects and hard to model with algebraic data types, some are the opposite. Knowing how to do both gives you more flexibility in modeling your domain. And like I said, mapping algebraic data types to typical OO concepts is not that complex: the data type becomes an abstract base class (or an interface, or an abstract trait), the data constructors become concrete implementation subclasses. That gives you an open algebraic data type. Restrictions on inheritance give you a closed algebraic data type. Polymorphism gives you case discrimination.
Aug 8, 2012 at 13:50 comment added Jörg W Mittag @Euphoric: So is Scala. In fact, Scala is probably more purely OO than C#, for example, C# has separate language constructs for first class functions (delegates), whereas in Scala first class functions are just a design pattern (any object which has an apply method is a function), albeit a design pattern with library support and syntactic sugar. You might also notice that the Scala example I gave is not very idiomatic code, precisely because I tried to use only the pure OO subset of Scala. I used only polymorphism, inheritance and encapsulation.
Aug 8, 2012 at 13:47 comment added Jörg W Mittag @TikhonJelvis: C# has subtyping, so it makes more sense to make Empty a subtype of ConsList<T> for all T. Since ConsList is covariant in T, you can make Empty a subtype of ConsList<T> by making it a subtype of ConsList<Bottom>, where Bottom is the bottom type, i.e. the subtype of all types. In Scala, Bottom is spelled Nothing, but apparently C# doesn't have a bottom type. (Or rather: it probably does have a bottom type, but it doesn't allow you to write it down.)
Aug 7, 2012 at 19:00 comment added Mauricio Scheffer @Euphoric C# has become a quite usable functional language with C# 3.0. First-class functions, built-in common functional operations, monads.
Aug 7, 2012 at 14:11 comment added Euphoric C# is OOP language. Solve problems using OOP. Don't try using any other paradigm.
Aug 7, 2012 at 13:08 answer added Petr timeline score: 25
Aug 7, 2012 at 13:02 answer added Peter Taylor timeline score: 2
Aug 7, 2012 at 12:44 comment added Jörg W Mittag @AakashM: That would actually be a good answer, can't believe I didn't find it.
Aug 7, 2012 at 8:35 comment added AakashM Of interest: Encoding algebraic data types in C#
Aug 7, 2012 at 8:10 history tweeted twitter.com/#!/StackProgrammer/status/232750649975111680
Aug 7, 2012 at 7:31 answer added Stephen C timeline score: 3
Aug 7, 2012 at 7:17 answer added Jan Hudec timeline score: 5
Aug 7, 2012 at 7:05 comment added Tikhon Jelvis I don't really know C#, but wouldn't you have to parametrize Empty on the list's type? That is, in Haskell [] :: [a], so I expect something like Empty<A>, the same as ConsList<A>. Then you could do something like class Empty<A> : ConsList<A>, assuming the syntax actually works that way :P.
Aug 7, 2012 at 6:38 history asked Jörg W Mittag CC BY-SA 3.0