These are chat archives for ramda/ramda

12th
Aug 2016
James Forbes
@JAForbes
Aug 12 2016 01:32

@rickmed its great to have types but typescript is currently not built for working with Monads/currying and other functional programming constructs. I think this will change overtime, I've seen some rumblings / issues about introducing nominal types and rank n types and that would help.

I still use it but it is more awkward than it could be.

Because typescript is focused on structural types, it always reports the base interface ( e.g. Monad or Functor as a return type even if it knows the type you passed in was a Maybe or an Either, you will need to constantly tell Typescript that return values are not just these basic interfaces. E.g.

var anotherMaybe : Maybe = someFunction(aMaybe)

And given that in functional programming we compose functions all day, that means there is a lot of times we have to help out the structural type inference.

Then currying is pretty awkward, you need to define multiple overloads for every function if you want type checking for all the possible invocations. I personally just write my own type defs that are all Unary to avoid this. And it works well most of the time, but it breaks down when you want to supply multiple arguments.

And let's not even get into placeholder support.

A lot of functions are just impossible to create an accurate type def in typescript. R.map is an example.

I think Typescript's mission was to allow typing codebases that are very fluid. Like a JQuery web app situation. But when you are doing functional programming things are very methodical and precise, so it often feels like the wrong tool for the job.

As for Flow, I haven't got any experience with it. But I've read through the docs a lot and it seems like its going to suffer from the same problems.
Rick Medina
@rickmed
Aug 12 2016 02:06
@JAForbes thanks for the detailed response! Yes. I've seen in the repos/examples and some own experimentation of all the things you point out and I agree. What I was anticipating the most was IDE type checking, the most I have gotten to work it was on typescript/vscode (it's pretty cool some of the time), but even so the set up and working with external libraries is a pain (specially the ones with no typings available). So the question was for the guys with experience (like you) is it worth the hassle?
also, not sure how far (and worth) can get out with inline typings, not sure if that was the best decision...
Ryan Zeigler
@rzeigler
Aug 12 2016 02:08
there is actually an open feature request somewhere in ts to support higher kinds
for me the annoying part seems to be when the type inference doesn't do the write thing.
which coupled with the fact the type system is unsound leads me to be ambivalent towards it
so I'm just happy using babel for now
James Forbes
@JAForbes
Aug 12 2016 02:14
@arzig yeah I've seen a few issues around higher kinds as well, but it seems like they don't really get it. The issues seem pretty unfocused. But here's hoping.
@rickmed I think it depends on your problem domain. For me I use it in some files where there are a a lot of stream transformations and its valuable to have type checks when I'm composing those streams. I guess the point is, you can get by with typescript it will just be really verbose and ugly. And the type inference is basically useless for fp @arzig said
But for some domains its worth the cost, but for most FP contexts, I think it isn't
I use browserify transforms so its pretty easy to opt in to different languages for different parts of your codebase. So if you just want to try it out, its not expensive to explore.

It might be worth looking at purescript. I wanted to use it but it looks like the module system is its own thing and that just won't work in my context.

F#'s Fable looks intriguing but I haven't had time to sink into it yet.

James Forbes
@JAForbes
Aug 12 2016 02:24
Actually I'm watching a purescript video right now and it looks like it is using commonjs which is contrary to what I had heard... So clearly I have no idea what I am talking about :P
Ryan Zeigler
@rzeigler
Aug 12 2016 02:28
probably just weird that they are commonjs but use bower for library management
that threw me a little bit when I looked at it
James Forbes
@JAForbes
Aug 12 2016 02:31

I was asking about this a few weeks ago in the purescript gitter and I was given the impression that the module system is totally independent. So maybe that video is out of date or something?

But if it is just commonjs, you could easily write a webpack/browserify transform, and I would use ps in a second if that were true.

Rick Medina
@rickmed
Aug 12 2016 03:33
@JAForbes cool. Thanks for the input. You must be referring to rxjs5 no?
The other day I was exploring some languages (this went a bit off topic), specially interested in the ones that could build "universal" apps, but honestly ended more undecided than anything :laughing:
^^functional static typed
James Forbes
@JAForbes
Aug 12 2016 05:41

@rickmed np :thumbsup:

Nah not Rx, https://github.com/paldepind/flyd

most.js is great too
Rick Medina
@rickmed
Aug 12 2016 06:01
@JAForbes does flyd have typescript types???
I've been wanting to try flyd so bad
James Forbes
@JAForbes
Aug 12 2016 06:09
Ummm, I don't think it does, but its really trivial to write a signature for flyd
Its basically just this:
interface IStream<T> {
    () : T
    (value: T) : this
    map<T2>( f: (value:T) => T2 ) : IStream<T2>
    end : IStream<boolean>
}
That signature is simplifying things because you rarely call the other instance methods directly, you'd use Ramda. Really all you need is
interface IStream<T> {
    () : T
    (value: T) : this
    end : IStream<boolean>
}
But you can also just use declare var require: any and then pull in modules without having type definitions for them
Rick Medina
@rickmed
Aug 12 2016 06:14
wait, I got confused when I read this "For me I use it in some files where there are a a lot of stream transformations and its valuable to have type checks when I'm composing those streams. "
James Forbes
@JAForbes
Aug 12 2016 06:15
Yeah, type checking on the contents of the streams
Rick Medina
@rickmed
Aug 12 2016 06:16
EG: you create function (with the above-like anotations) constructed from the composed flyd operations?
James Forbes
@JAForbes
Aug 12 2016 06:18
So say I have a stream of numbers
var stream : IStream = require('flyd')

var numbers = stream<number>()

// typescript knows `n` is a number
// typescript knows strings is Stream<string>
var strings = numbers.map( n => n.toFixed(2) ) 

numbers('this is not a number') // <-- type error :)
So that scales up to really complex structures
So I might have a stream that is a index of some prased json response form the server. Well I can have streams that receive and transform that stuff, and I get type checks on the transformations I'm doing
Rick Medina
@rickmed
Aug 12 2016 06:20
need to check how flyd functions look like but I get the idea. Pretty cool
James Forbes
@JAForbes
Aug 12 2016 06:20
flyd is just a tiny api, but it plays well with ramda
So you don't need to learn a bunch of custom rxjs operators, you can reuse normal functions used in ramda a lot of the time
Most has a larger api but a lot of the same benefits as ramda, they both implement the Applicative Functor spec of fantasy land
and I think in most, the streams are Monads too
Rick Medina
@rickmed
Aug 12 2016 06:25
so with flyd you would use mostly ramda to map, flatmap, combine, etc streams?
thus, as you said, you'd only need the Istream interface to get all the typescript type checking?
Ryan Zeigler
@rzeigler
Aug 12 2016 13:17
@JAForbes or @rickmed does flyd not expose join?
Rick Medina
@rickmed
Aug 12 2016 15:20
@arzig it exposes combine, is that what you mean? either way you would have to declare its type, the above comment was to profit from the existing ramda types
James Forbes
@JAForbes
Aug 12 2016 15:29

@rickmed yeah you can use R.traverse,R.sequence,R.lift,R.map as operations and then basically any other ramda function as a transformation

@arzig flyd doesn't have join or chain, its just an applicative functor, but... you can go a long way with ap/lift.

Rick Medina
@rickmed
Aug 12 2016 15:32
oh yes I forgot about join.. (just starting to learn about fp... :smile: )
Roman Pominov
@rpominov
Aug 12 2016 19:58
Anyone want to help with logo for Static Land (spec similar to Fantasy Land)? rpominov/static-land#12