News for hackers. Stuff that matters.
Re:A Farewell to FRP by timroy on Tuesday May 10, 2016 @11:15AM (#11667791)
This looks very cool.

In ClojureScript, we have the re-frame pattern/framework, which is built on Reagent, which is a ClojureScript wrapper of React.

re-frame is all about subscriptions, using a "big atom" to hold application state client-side. Seeing Elm implement the same subscription pattern makes it look pretty tempting.

My understanding is that ClojureScript and Elm have some similarities - functional, pleasant to work with - with one significant difference being that Elm is typed.

Re:A Farewell to FRP by hkjgkjy on Tuesday May 10, 2016 @12:36PM (#11668468)
Elm is typed, Clojurescript is homoiconic. 2 great features.

Wondering if you could make a lisp where `lambda` or `fn` required type annotations, such as

    (defn add 
      [int -> int -> int] ;; type annotation
      [x y] ;; arguments list
      (+ x y))
Then it would be homoiconic - something that has saved me hundreds of lines of code (and the less code, the less bugs as a rule of thumb).

Then every function down to the very basic lisp functions would have types. Dunno how doable this is - but it doesnt matter. Someone implemented it in Common Lisp in the 80s I'm sure.

Re:A Farewell to FRP by hencq on Tuesday May 10, 2016 @12:57PM (#11668659)
There's Typed Racket [1] and for Clojure there's core.typed [2]which do pretty much that. For Clojure there's also Schema [3], which is a bit lighter weight (it's not a full type system), but still gets you some of the benefits like validation and documentation.

[1] https://docs.racket-lang.org/ts-guide/ [2] https://github.com/clojure/core.typed [3] https://github.com/plumatic/schema

Re:A Farewell to FRP by hkjgkjy on Tuesday May 10, 2016 @01:19PM (#11668838)
Neither fit the bill though - because not every function ever written in the language is annotated. To be nice to use, it should be an all-or-nothing affair.

I say this as a huge clojure fan - my clojure programs with dynamic types work great. I rely on predicates (functions ending in -?) in I/O, otherwise I'm sure things work.

Re:A Farewell to FRP by sgrove on Thursday May 12, 2016 @08:56PM (#11687902)
Why is annotation important? I agree it needs to be possible, but ultimately I want to push the majority off into inference, and only explicitly annotate when necessary or formalizing interfaces OCaml-style.

Though I sure do wish I could have lisp (or clojure, specifically) syntax in OCaml-land.

Re:A Farewell to FRP by eggy on Tuesday May 10, 2016 @02:19PM (#11669326)
How about Shen [1]?

A Lisp with types, built-in Prolog, optional lazy evaluation and more. It scratches my Lisp/Haskell love affair.

[1] http://shenlanguage.org/

Re:A Farewell to FRP by mst on Tuesday May 10, 2016 @01:37PM (#11668990)
This is why (ignoring the batshit syntax) I'm quite fascinated by urbit's language hoon, since it handles type signatures by evaluating the function with type objects rather than straight arguments, so the above without the annotation would already be strongly typed and valid across anything that supported +
Re:A Farewell to FRP by masklinn on Tuesday May 10, 2016 @12:52PM (#11668607)
There's Typed Racket and Clojure's Core.Typed. In Common Lisp you can `declaim`/`declare` attributes to functions and values, and many implementations allow `declaim`-ing types. It's also common for them to propagate and check type assertions at compile-time e.g.

    (defun foo (bar)
      (if (numberp bar)
        (car bar)
      x))
should error out in SBCL because BAR is a number but CAR takes values.
Re:A Farewell to FRP by wtbob on Wednesday May 11, 2016 @10:06AM (#11675361)
> Wondering if you could make a lisp where `lambda` or `fn` required type annotations

…

> Someone implemented it in Common Lisp in the 80s I'm sure.

Even better, it's a standard part of Common Lisp: functions default to being 'typed' to take the universal type, but annotations can be used to declare any types you want (to include types like (integer 3 27), which specifies an integer between 3 and 27), which can be compiler-enforced.

I really don't understand why Common Lisp doesn't see more use. It's modelling clay for computation.

Re:A Farewell to FRP by platz on Tuesday May 10, 2016 @08:38PM (#11671841)

   \* add.shen *\

   (define add
      {number --> number --> number} \* type annotation *\
      X Y ->                         \* arguments list  *\
      (+ X Y))
Re:A Farewell to FRP by eggy on Wednesday May 11, 2016 @08:28AM (#11674611)
There was a small thread on the Shen Google Group about adding docstrings [1].

There is an BSD version of Shen that can be forked and docstrings added by whomever wants to pickup the work. The language's footprint is small enough now at the moment, that now's the time to get the first chunk done.

The BSD version is pretty impressive, and could be turned into a great project if people picked it up. A lot of interest has been expressed, but it is the commercial version that is moving ahead with lots of improvements. Shen's creator, Mark Tarver has added Griffin, an optimizing compiler, concurrency, and HTML generator in the form of SML (Shen Markup Language).

It is a very fun project. The small set of instructions it is based upon Klambda, has since been ported to many languages - Ruby, Python, Lisp, Haskell and more. The SBCL port is the main one. Aditya Siram (Deech) has just created an Elisp port, shen-elisp! [2]

[1] https://groups.google.com/forum/#!topic/qilang/FHUNMvOyu2U [2] https://github.com/deech/shen-elisp

Re:A Farewell to FRP by Morgawr on Tuesday May 10, 2016 @02:05PM (#11669234)
I personally use ClojureScript with type annotations from Plumatic (former Prismatic) Schema and it works really well. Obviously it's not the same as an actual typed language, but it gives me a good-enough starting point to leverage some typing information and perform some rudimentary (runtime) type checking. I also feel it's really nice as some kind of "inline documentation" to be able to see the type of your parameters (obviously this is a given benefit for statically/explicitly typed languages).
Re:A Farewell to FRP by timroy on Tuesday May 10, 2016 @04:43PM (#11670509)
I have heard only good things about Schema, and I probably should have invested the time to understand and use it more intensively.
Re:A Farewell to FRP by Reefersleep on Wednesday May 11, 2016 @11:24AM (#11676133)
Just dive into it. After wanting to be a bit more descriptive and assertive about the input and output of certain functions in some code I was writing, I must have spent all of half an hour reading documentation and successfully adding Schema to my code. Might be a bit of a rose-tinted memory here in respect to the pastimate :) But it certainly is both easy to understand and use.
Re:A Farewell to FRP by jiyinyiyong on Tuesday May 10, 2016 @11:20AM (#11667820)
Might be off topic but I was interested in the "a big atom". Reagent is using a big atom and some small atoms to simulate component state -- which breaks hot code swapping. And I tried a way to abstract out component states into a single atom to fix it by building my own React like library. Now it's "two big atoms" on my side.
Re:A Farewell to FRP by timroy on Tuesday May 10, 2016 @12:25PM (#11668368)
Yeah, after the app grew a bit, I had state scattered here and there. re-frame solves this with a big atom, and avoids expensive rendering every time the big atom updates with subscriptions. Subscriptions hold reactions, which only update if the underlying value changes.

The re-frame readme is epic and worth reading just for its own sake: https://github.com/Day8/re-frame

Not to get off-topic though! I am used to working with dynamic languages, but I really should work with a typed language. Elm looks like it offers many of the benefits of ClojureScript, but with typing as well.

Also, ClojureScript lets you write HTML and CSS in your code, but a quick web search indicates Elm may have gone further with incorporating CSS (?).

Re:A Farewell to FRP by pseudonom- on Tuesday May 10, 2016 @01:38PM (#11668996)
Can you talk a little more about your thoughts on one big atom? I've been looking at Redux and they also seem to follow this approach. The re-frame readme quotes the Elm Architecture as justification, but that same document goes on to describe nesting https://gist.github.com/evancz/2b2ba366cae1887fe621#nesting.

I come from a Haskell perspective and having one big blob of state sounds to me like it makes your type signatures less informative and increases the scope for error.

Re:A Farewell to FRP by timroy on Tuesday May 10, 2016 @04:42PM (#11670501)
So, the one big atom solved two problems for me.

First, in Reagent/FRP, I was updating a view based on the value of an atom. This meant I had different default values in different atoms. The big atom let me unify where I stored values, and reuse values, without a performance hit. Second, the big atom made storing application state trivial: you can just throw the map/record in Redis or something.

However, the big atom is just a big map, and keys can be paired with any value, so it is not enforcing types. From a Haskell perspective (where I understand the program almost falls out of the types you define!), this probably does increase the scope for error.

This can be mitigated with Schema (which I never used effectively), logging changes to the console, and being able to see your default map easily (like, there's a map in one file which I load upfront, so I can see what values are there).

I'd welcome hearing from anyone with a more advanced or precise use of re-frame state.

Re:A Farewell to FRP by Skinney on Tuesday May 10, 2016 @12:42PM (#11668533)
Elm incoperates CSS the same way Clojurescript and React incorporates CSS.
Re:A Farewell to FRP by timroy on Tuesday May 10, 2016 @03:46PM (#11670041)
Thanks, good to know.