Live data from Hacker News

Why OCaml, Why Now?

spyder.wordpress.com

41–50 of 106 posts

Re: Why OCaml, Why Now?

#41
post #7

Earlier quoted context omitted.

I write all my javascript in haskell, and haven't had any problems. What do you need/want "DOM bindings" for?

As someone who would like to write his javascript in Haskell, how do you put text on the page without interfacing with the browser's DOM?

I'm curious about this as well so I did some searching.

Fay[1], a subset of Haskell that compiles to JavaScript, seems to be the primary choice. There are DOM and jquery bindings for it and this blog post[2] looks like a great introduction.

There are other options, this [3] article outlines a number of them as a greater overview of both server and client side programming with Haskell. I also found an intriguing article [4] on the Haskell site but it appears to be out of date, referencing libraries that are no longer in development.

[1]https://github.com/faylang/fay/wiki

[2]http://ocharles.org.uk/blog/posts/2013-12-23-24-days-of-hack...

[3]http://www.stephendiehl.com/posts/haskell_web.html

[4]http://www.haskell.org/haskellwiki/Haskell_in_web_browser

Re: Why OCaml, Why Now?

#42

I'm glad that the author is picking up a new functional programming language, but choosing OCaml over Haskell because of support for the Javascript implementations strikes me as choosing a BMW over a Mercedes[0] because of the number of cupholders it has. If you don't have a particular goal in mind (ie, "I work at Jane Street and need to be compatible with our existing code"), there are a number of other factors in t…

What's weirder about this is Haskellers have no problems using Fay, PureScript, and Haste for JavaScript.

Re: Why OCaml, Why Now?

#43

Earlier quoted context omitted.

It sounds like you have a very language-centric view of the world. In practice, deployment is everything. (Why do people write code in Objective C? Because iPhone.) Having a solid implementation for your target platform is very good reason to pick a language.

> It sounds like you have a very language-centric view of the world. > Having a solid implementation for your target platform is very good reason to pick a language. I'm not sure where you got that out of my comment; it was exactly the opposite. My point was that neither OCaml nor Haskell have particularly strong implementations in this area (to my knowledge). Last time I checked, the ability to write Javascript usin…

Haste is a strong, useful, and impressively complete Haskell to JS compiler.

Fay is used in production apps as well.

PureScript is less mature still but pretty nice.

Re: Why OCaml, Why Now?

#44

Considering how strongly opposed the author is to dynamic typing, I'm actually kind of surprised they'd consider OCaml's type system to be acceptable. Technically, yes, it's a statically typed system. But its use of structural typing instead of nominative typing effectively means it takes half the compiler assistance you can get out of static type checking and chucks it out the window. Using structural typing means t…

Abstraction provides the equivalent of nominative typing. It is easy to differentiate between 12 meters and 12 Newtons with OCaml's type system.

In general, it is easy to get nominative behaviour out of a structural system. It is much harder to get structural behaviour out of a nominative system.

Re: Why OCaml, Why Now?

#45
post #3
post #2

This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line. The only real reason that I can see to choose OCaml over Haskell is that if you learn OCaml, you might be able to work at Jane Street. Is there a strong argument for abandoning my Haskell-ing for OCaml?

> This might be entirely superficial of me, but I always preferred Haskell over OCaml simply because OCaml required me to type ";;" after every line. That's easily fixed: only the toplevel requires ;; (to commence evaluation of the phrases you've typed in). Just don't use it in normal code and everything will parse fine.

> everything will parse fine.

That's an exaggeration. There are circumstances in files where it's necessary. I didn't realize this, which hung me up for a long time.

Re: Why OCaml, Why Now?

#46

Considering how strongly opposed the author is to dynamic typing, I'm actually kind of surprised they'd consider OCaml's type system to be acceptable. Technically, yes, it's a statically typed system. But its use of structural typing instead of nominative typing effectively means it takes half the compiler assistance you can get out of static type checking and chucks it out the window. Using structural typing means t…

You may be confused by the fact that the type system will notice the equivalence of two types if the implementations of both are public eg

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
    end :
    sig
       type newtons = int
       val inc : newtons -> newtons
    end

    M.inc 1 (* this works *)

    module M = 
    struct
       type newtons = int
       let inc some_newtons = some_newtons + 1
       let in_newtons x = x 
    end :
    sig 
       type newtons
       val inc : newtons -> newtons
       val in_newtons : int -> newtons
    end

    M.inc 1 (* type error *)
    M.inc (in_newtons 1) (* this works *)
The use of hidden types in OCaml gives far better control over encapsulation and implementation hiding than any over language I've used.

Re: Why OCaml, Why Now?

#47
post #25

"...Facebook created ... a statically typed PHP variant..." - so happy to see another major tech company understand the merits of static typing.

... and so sad about them further fragmenting the ecosystem with yet another language.

Re: Why OCaml, Why Now?

#48
post #29
post #20

I've found it interesting that OCaml hasn't had more interest given the amount of recent momentum in Haskell. Haskell is an Ivory Tower. The features that generally draw one to the language also tend to be the things that eventually push one away. Haskell has grown a lot over the years however as the language evolves to allow general programming within a pure framework. OCaml on the other hand tends to make a comprom…

I feel it's similar to any competitive environment: differentiation requires making strong tradeoffs. Haskell's choice of tradeoffs---while initially very ivory tower---have led to to become a strongly differentiated language. You not only learn how HM typing and full commitment FP feel, but also how to structure code purely, compose effects, and abuse laziness. So for the very same reasons you give---Haskell has mad…

Another big obstacle was that the INRIA license effectively prevents forking the language (you can only distribute modified compilers as original source + patch, not as eg a github repo) so for a long time there was a bottleneck on the language evolution. Lots of useful extensions (eg delimited continuations, staging) wilted and died because of that.

The rise of OcamlPro and Ocaml Labs does give me hope for the future of the language. There is already renewed momentum behind fixing packaging and handling multicore.

Now if someone would just figure out ad-hoc polymorphism (just pick one of the dozens of propasals) and maybe even document camlp4/5....

Re: Why OCaml, Why Now?

#49
post #11

Earlier quoted context omitted.

As someone who would like to write his javascript in Haskell, how do you put text on the page without interfacing with the browser's DOM?

Is that a trick question? I don't know how or why you would try to do that.

I assure you that it's not a trick question, just a poorly worded one.

Imagine that I'm making a page that converts meters to millimeters. The obvious part of the haskell code is

convert :: Double -> Double convert = 1000 *

The part which isn't obvious to me is how I get input from the user or display the result. I know how to do that in the IO monad through standard haskell, but I wouldn't know how to handle it in Haskell compile to javascript for the web browser. I would have thought that you would need a binding to the DOM to read from forms and the like.

Re: Why OCaml, Why Now?

#50

Earlier quoted context omitted.

As someone who would like to write his javascript in Haskell, how do you put text on the page without interfacing with the browser's DOM?

http://elm-lang.org/ for example. To display text in the browser you would use - main = plainText "Hello, World!" From the page: "Elm is a functional language that compiles to HTML, CSS, and JavaScript". So yes, technically this is working with the DOM. But you are not writing code that interacts with a "DOM binding" directly per se.

I've played with Elm for a toy project before and I do have high hopes for it. I also think it's the greatest monad tutorial ever - you don't truly miss them until they're gone.

(To clarify: At the time that I last used Elm, the Signal type was a functor, but was intentionally being kept from being a monad for design reasons. Working around this restriction tought me a lot on why I needed monads.

Post reply on HN