Live data from Hacker News

Thinking in Types

robots.thoughtbot.com

101–110 of 124 posts

Re: Thinking in Types

#101
post #32
post #4

Earlier quoted context omitted.

I understand the critique being made, but this seems like a slightly outdated view of Haskell. There is quite a bit of software being written in Haskell these days. One project that got some press recently is a long existing project that recently went open source, Cryptol [0]. While lots of projects in Hasekll continue to be libraries written for Haskell, there are also lots of languages using Haskell for their imple…

To be fair most of the trending github projects are libraries for use in Haskell. There are very few actual applications - there is pandoc, git-annex and hakyll and that is it.

hakyll is a library and not an application, technically, as is xmonad, another famous haskell "application". pandoc is often used as library as well.

the point is, that often you have one-off applications that are just a few lines and use these libraries.

Re: Thinking in Types

#102
post #94

Earlier quoted context omitted.

My preferred way to approach this, in Haskell specifically, is to use records as a naïve encoding of objects or interfaces. For example, expanding on the functionality a little bit: data GameEntity = GameEntity { render :: IO () , getPosition :: Point , setPosition :: Point -> GameEntity } makeBall :: Point -> GameEntity makeBall pos = GameEntity { render = myRender , getPosition = pos , setPosition = mySetPos } wher…

> What I've done is used a record type to encode the interface that it's supposed to expose, I love how Haskellers (in general, not you in particular) bash OO and then come up with the exact same technique of simulating OO that is used in C (a struct of function pointers). Something which OO languages provide out of the box (interfaces, virtual methods, etc). Now, let's take this a step further: how would you simulat…

I don't think Haskellers bash OO that much. They bash some of the trappings of it. GoF is usually a typesafe library in Haskell because it has better abstraction capabilities. Functions form better fundamental units than objects do (but are a form of "object" themselves). Composition is better than inheritance. Classes are not generally so useful.

Really, I think Haskell has a super great object system. It's just (a) not the central conceit and (b) so naturally embedded in the language that you can program for a long time without even noticing it's there.

Codata typically indicates you're looking at an object. In Haskell, due to it being non-terminating as a language, codata and data are unified so most "objects" look identical to their non-object form. You can also notice them by definitions based on eliminators. Automata are a good example

    newtype Auto f i o = Auto { run :: i -> f (Auto f i o, o) }
You can also look for objects as ADTs. When you do this you can get a natural embedding of a prototype-based language. (http://www.cs.ox.ac.uk/jeremy.gibbons/publications/adt.pdf)

    data ADT f = forall st 
               . ADT { unfold :: st -> f st
                     , state  :: st
                     }
Here, the internal state type `st` is closed over as an existential value—when you create a new ADT you can pick what st is but the type system then ensures that nobody ever can access that type again. Instead, you have to use the `unfold` elimination form which projects the state into a "class" `f` (represented as a Functor, but that's immaterial) which defines a signature of methods over the abstract state. Auto, from before, is definable this way.

    data AutoClass st o = 
      AutoClass { next :: st
                , out  :: o
                }

     type Auto = ADT AutoClass
Subtyping occurs naturally with quantified types like the existentially-typed `st` variable or the universally quantified types you see all the time in type signatures. It's a more natural form of subtyping since it's all defined by increasing typeclass bounds. Something like

        {C} : set of constraints    Ci : constraint
    ------------------------------------------------------
    forall a . {C} a => a :> forall a . ({C} a, Ci a) => a
This guarantees that these these two types are good "subtypes on eliminators" which satisfies the Liskov Substitution Principle if not some of the more strict definitions of subtype "niceness".

Double/Multiple dispatch is trivially handled in Haskell since polymorphism is solved by an entire Prolog embedded in the type system.

The thing is that Haskell also has initial data, things like finite lists are better thought of as a big tree of constructors

    1:(2:(3:(4:(5:[]))))
and then pattern matched upon (defining catamorphisms)

    sum :: [Int] -> Int
    sum (a:bs) = a + sum bs
    sum []     = 0
and this pattern is perhaps a little bit emphasized in mainstream Haskell because it sides on the "functional" side of the expression problem. It doesn't mean, though, that Haskell doesn't like the "object oriented" side, but instead that Haskell favors both.

Re: Thinking in Types

#103
post #33

Earlier quoted context omitted.

Have you looked at the Haskell QML bindings? They generally work for cross platform requirements. http://hackage.haskell.org/package/hsqml-0.1.1/docs/Graphics...

Yes. It does not compile on my Mavericks machine. Same with every graphics package I've tried.

Have you tried using cabal sandboxes to work around your build issues?

Re: Thinking in Types

#104
post #22

On a related note: The article (quite reasonably) avoids discussion of the graphics library, but I want to know more about that side of things. I wish graphics got more attention in the Haskell ecosystem in general. The options right now are pretty dismal. There is quite literally not a single Haskell graphics or GUI package that I've been able to install on OS X. I'd love to use Haskell to build games or desktop GUI…

Have you looked at the Haskell QML bindings? They generally work for cross platform requirements. http://hackage.haskell.org/package/hsqml-0.1.1/docs/Graphics...

The QML bindings are great! They are still fairly new and lacking some features but it seems as though Qt5 support was just added.

Re: Thinking in Types

#105

Earlier quoted context omitted.

Why do you need to build the latest and greatest? Building the very latest gcc/clang is also going to be a PITA. In either case, there's a perfectly servicable binary distribution and the stuff packaged in my OS's repo is still plenty usable.

> Why do you need to build the latest and greatest? Why shouldn't I? When Scala 2.11 was released I downloaded the binary, changed my PATH, fired up a new terminal and started exploring the latest release. Takes 2 minutes or so. I'd like to do the same with Haskell. 7.8 looks to have significant language improvements that I want to explore vs. read about and be stuck on 7.4.1 (Fedora 18's provided version).

So go ahead and download the binary:

https://www.haskell.org/ghc/download_ghc_7_8_2#binaries

You're not comparing apples to apples.

Re: Thinking in Types

#106
I think a better example is needed. The example's solution to the Haskell heterogeneous list "problem" could be implemented in other statically typed languages (C++, Java) although it wouldn't be necessary to do so.

I don't see how the Haskell type system is safer in this example but I feel there's something interesting there which I don't understand. Can someone explain the advantage of type classes over what could be done with interfaces and templates in C++?

Re: Thinking in Types

#107

Earlier quoted context omitted.

> Why do you need to build the latest and greatest? Why shouldn't I? When Scala 2.11 was released I downloaded the binary, changed my PATH, fired up a new terminal and started exploring the latest release. Takes 2 minutes or so. I'd like to do the same with Haskell. 7.8 looks to have significant language improvements that I want to explore vs. read about and be stuck on 7.4.1 (Fedora 18's provided version).

So go ahead and download the binary: https://www.haskell.org/ghc/download_ghc_7_8_2#binaries You're not comparing apples to apples.

> So go ahead and download the binary

Indeed I did just that, the issue is that the only binary distributions for Linux are CentOS 6 and some flavor of Debian, both of which are dinosaurs compared to any modern distro. The long and short is the installation fails due to a missing dependency on antiquated libgmp.so.3, thus cooking my CPU for an hour and building from source.

If you want to talk about barriers to Haskell adoption, this is certainly one of them.

Re: Thinking in Types

#108

Earlier quoted context omitted.

So go ahead and download the binary: https://www.haskell.org/ghc/download_ghc_7_8_2#binaries You're not comparing apples to apples.

> So go ahead and download the binary Indeed I did just that, the issue is that the only binary distributions for Linux are CentOS 6 and some flavor of Debian, both of which are dinosaurs compared to any modern distro. The long and short is the installation fails due to a missing dependency on antiquated libgmp.so.3, thus cooking my CPU for an hour and building from source. If you want to talk about barriers to Haske…

"both of which are dinosaurs compared to any modern distro."

Without any clue of what constitutes "any modern distro" in your mind, I don't see how this can proceed further. Note that Centos 6.5 and Debian wheezy are the latest from their respective projects. I believe the Debian version will happily install under recent Ubuntu and derivatives.

I'm sorry your preferred distro doesn't have better support.

Re: Thinking in Types

#109
post #93

Earlier quoted context omitted.

I wasn't making any point. Fwiw, I have been able to meet my own (quite limited) gui needs in Haskell with gtk... Edit: On reflection, I find your assertion a little strange here. Anecdotal failure to build on one particular setup doesn't seem like a particular highlighting of bad bindings.

I can add another anecdote. In almost 10 years now of using Haskell on Mac, Linux and Windows, I've never once had any success building any GUI binding for Mac OS, despite trying every one I could find (gtkhs included) at least once a year on many different OS/hardware combinations. (unless you count HOC, but I never actually got it working as-was - I brought it back from bit-rot on a couple occasions, adding ObjC 2…

Huh. It is sounding like there's an issue with Mac GUIs, then. Maybe the Mac/Haskell overlap is just too small? Both are small-to-niche... It would probably make sense to get a group oriented around getting that fixed up. For myself, I'm meeting my needs - and both 1) more GUI apps and 2) more Mac support are almost entirely orthogonal to them, so I'm not likely to participate.

Re: Thinking in Types

#110

Earlier quoted context omitted.

Partially because McDonalds/PHP lets you eat/deploy by cramming/uploading the food/file directly into your mouth/server. No utensils/tools required.

> No utensils/tools required I think a more apt analogy would be: no furnace to forge your own cooking utensils (hour long build from source to get latest and greatest [7.8] installed) which you use to prepare the meals (wait for your application to compile) that you then stuff into your mouth (deploy to server).

The 7.6 packaged in Debian is perfectly usable and compatible with everything I've wanted to grab from Hackage. There's a few new bells and whistles in 7.8 (like TypedHoles and -fdefer-type-errors) that I'm looking forward to, but their lack doesn't mean I can't build existing code and when developing new code it just means I lack some new tools. Since these tools are lacking everywhere else, their temporary lack is obviously not keeping people away from Haskell.

Basically, you can get yourself access to a furnace to forge your own melon baller, but you've already got a spoon, and someone else will be shipping you a melon baller next month.

Post reply on HN