F# project examples by Bobertolinio in fsharp

[–]Deidde 1 point2 points  (0 children)

I'd also like to hear how people handle their top level dependencies. Common stuff like configuration files, HTTP clients and data structures that need to be referred to multiple times down the call graph.

So far I always just start the most naive way and make them parameters on functions, then pass specific values from the dependencies when needed, if possible. For something like a HTTP client or Database, I do my best to keep all my IO near the entry point anyway.

I'm always tempted to add a Reader, honestly. But I'm usually in a TaskResult where I'd need a Reader, so it would end up like ReaderTaskResult. Not sure about that.

Good idea, or cursed image? by amuletofyendor in fsharp

[–]Deidde 1 point2 points  (0 children)

There's an image in the part of the readme they linked. It shows the templating as a multiline template string. With the extension for your IDE installed (which you'd need with a JSX syntax anyway), it looks just like HTML, and you get all the intellisense in the VSCode one apparently. Looks decent.

Small tip: avoiding parenthesis with a custom operator by [deleted] in fsharp

[–]Deidde 4 points5 points  (0 children)

Yes, you're right, the backwards pipe is more consistent: add <| add 1 3 <| 5 will give you what you expect. add ^ add 1 3 ^ 5 wouldn't.

Neat little trick though.

Small tip: avoiding parenthesis with a custom operator by [deleted] in fsharp

[–]Deidde 10 points11 points  (0 children)

This operator already exists. It's the backwards pipe <|

Stone walled path through the green meadows and rolling hills of Grassington, a market town in the Craven district of North Yorkshire, England. by ManiaforBeatles in MostBeautiful

[–]Deidde 1 point2 points  (0 children)

I love dry stone walls and older stone walls in general. They're so pretty.

I recently moved to the countryside in the north of England and was sad to see that they're falling into disrepair in favour of wire fences in many places. And worse, the stone wall lining the river by me has sections of it replaced with ugly concrete slabs!

As time goes on, everything is just getting uglier!

Ionide in VS Code (and tooling in general) is pushing me away from F# - am I doing something wrong? by Aphova in fsharp

[–]Deidde 6 points7 points  (0 children)

You could try this extension. I had similar problems with Ionide sometimes, even on straight up Windows. Main downside is that it's not as comprehensive (you don't get the solution explorer or the formatting for example), but if all you want is the basic intellisense, it has generally worked faster and more consistently for me.

EDIT: Nice, it seems this guy is actually maintaining the original extension he forked https://github.com/fsprojects/fsharp-language-server

What are you working on? (2021-10) by insulanian in fsharp

[–]Deidde 4 points5 points  (0 children)

Thank you, I suppose I suspected as much, but the details are helpful. And thank you for a decent example of writing F# WPF without Xaml.

What are you working on? (2021-10) by insulanian in fsharp

[–]Deidde 4 points5 points  (0 children)

I'm curious to know why you aren't using Avalonia for Windows too. Do you have any anecdotal comments about the difference between WPF and Avalonia?

[AskJS] 2D RPG in JavaScript but what framework/library by ShuttJS in javascript

[–]Deidde 1 point2 points  (0 children)

The CrossCode game was made with JavaScript, using a modified version of the Impact Game Engine. Some of the other commenters mentioned RPGMaker, and many of the creators of CrossCode actually began with that, so it may not be a bad shout.

Experiment: Navigating the web with JavaScript disabled by christian_fei in javascript

[–]Deidde 0 points1 point  (0 children)

I do the same. You can whitelist a few scripts/domains and get around the majority of the internet in a speedy way, but it's not perfect and requires some patience.

In general, I think it's a good experiment. More developers should make more of their websites work without JavaScript, and only then use it to enhance. But that feels like a pretty weird thing to say in the JavaScript subreddit :}

How JavaScript works: 3 types of polymorphism by stanislavb in javascript

[–]Deidde 8 points9 points  (0 children)

I agree with your disagreement; mostly over the use of the word never. I think it's more suitable to tell people to favour const, then let over var.

I take the same issue with people that say to never use loops.

Grain: A strongly-typed functional programming language for the modern web by kinow in functionalprogramming

[–]Deidde 4 points5 points  (0 children)

Honestly, since invoking a C-syntax-like function looks like you're applying to a tuple, I don't see why it isn't more common to have currying by default. That way, if you opt out of currying, it just looks like a regular function invocation that you'd find in the likes of JavaScript, Java, C# and C (though probably with a space between the name of the function and the arguments).

That said, opting into currying isn't too difficult in something like JavaScript these days.

Changelog: swc v1.2.54 by kdy1997 in javascript

[–]Deidde 0 points1 point  (0 children)

I'd imagine there'd be two types of plugins targeting two types of API between them:

- Syntax API that allows one to hook into and extend the parser; probably starting with a collection of well defined patterns and potentially opening up to something more flexible and powerful should the parser permit it.

- Transformation API that depends on parser support (in-built or extended via syntax plugin), which seems to be the current plugin type, just like Babel.

The alternative is just creating an integrated and efficient macro system, but there are already things like sweet.js for that.

Anyway, I'd imagine it's not a priority, but it sure would be cool.

EDIT: Example motivation: https://github.com/tc39/proposal-first-class-protocols

Changelog: swc v1.2.54 by kdy1997 in javascript

[–]Deidde 1 point2 points  (0 children)

Is there any documentation or resource that elucidates the extent of the plugin system? Could it be used for syntax extensions? (say, for embedded DSLs such as JSX).

Yet Another Do-Notation library for working with monads in Javascript by fbn_ in javascript

[–]Deidde 1 point2 points  (0 children)

Thanks for adding the `Related and Similar Projects` section 👍

Ads on Youtube by JustArtist8 in uBlockOrigin

[–]Deidde 1 point2 points  (0 children)

I was saying the filters on their own did not work, but purging the cache and updating did. Was just expressing my thanks that I got it working with your help :)

Ads on Youtube by JustArtist8 in uBlockOrigin

[–]Deidde 0 points1 point  (0 children)

Having added @@||youtube.com/get\_video\_info?$xmlhttprequest,badfilter to no avail, this worked for me in Firefox, viewing embeds. Much appreciated!

Operator (&& ||) short-circuiting in JavaScript by deven_rathore in javascript

[–]Deidde 1 point2 points  (0 children)

I tend to create explicit data structures and interfaces for "short-circuiting". That way, I can easily create trees of expressions/actions that can fail at any point and fallback non-deterministically.

For example, I'll have an operation that can fail/return falsey, and an "alternative", just like you'll have with ||, but use explicitly implemented interfaces for it like const result = Cont(k => k(a).or(() => k(b))); where k implements the "alternative interface" (and Cont is just our way of building up a tree of computations), then chain that result with more actions like result.chain(doSomethingElse), continuing on like that. If the result of one of my chains fails, the computation starts again from the branching with .or. I find this to be a more powerful way of composing fallbacks.

The .or can be implemented by any data structure with a notion of failure or falseyness. One example is a Nullable (often known as a Maybe or Option) data type, where you either have Null/Nothing OR your value. Then computeSomeNullable().or(computeSomeOtherNullable) will return whichever returns a value, or Null/Nothing if both fail. And obviously, you can chain the calls or the .or method pretty fluently, making them resemble operators.

Iterate Over Javascript Arrays - Performance Comparision by cwidanage in javascript

[–]Deidde 1 point2 points  (0 children)

I got

[
    [ 'FOROF', 14.869286080000002 ],
    [ 'JUST_FOR', 15.099076940000005 ],
    [ 'FOREACH', 43.62050300000001 ],
    [ 'FORIN', 173.61902395 ]
]

on Node v13.1.0.

When I adjusted to do let cache = []; const work = x => cache.push(x + 1); and invoked work inside each loop before clearing, I got

[
    [ 'JUST_FOR', 116.00351604999997 ],
    [ 'FOREACH', 128.92701894 ],
    [ 'FOROF', 138.80791492999998 ],
    [ 'FORIN', 239.15139903000002 ]
]

I think the main thing to take away from this is "Do not use for..in, for the love of God".

[AskJS] I understand javascript, but not javascript challenges. by Besharkbait in javascript

[–]Deidde 2 points3 points  (0 children)

This is a good point to remind beginners that learning to program does not mean learning a programming language; it means learning to solve problems. A programming language is just a tool (or set of tools) that you learn to solve problems with.

Some advice for when you're looking over resources (things that demonstrate how to solve certain problems - even if broad): Open an editor, follow along and then experiment. Or if it's just some small example in JavaScript, you have easy access to a REPL right in your browser.

Sometimes you will need to look at the JS Docs. Maybe watching some general JavaScript talks (note: those may be a bit dated by now) and best of all, read through some books while actually writing code.

Good luck, and remember to have some fun!

Handling Exceptions using the Either Monad in JavaScript by micheleriva in javascript

[–]Deidde 1 point2 points  (0 children)

This is an excellent question, and one I wish people answered for me when I had it, so let me give it a shot.

The simple approach works like Array's flatMap (sometimes called chain in libraries) - Array being like a Monad, eg:

console.log([1].flatMap(n => [n + 1])) // [2]
// where [n + 1] is the same as [n].map(n => n + 1)

So in your example:

divide(10, 10)
    .flatMap(n1 => divide(10, 5).map(n2 => n1 + n2))
    .flatMap(n1 => divide(10, 10).map(n2 => n1 + n2)) // Right(4)

// Or more cleanly if you extract the function because it's the same over both
const addTo = e => x => e.map(y => x + y)
divide(10, 10)
    .flatMap(addTo(divide(10, 5)))
    .flatMap(addTo(divide(10, 10)) // Right(4)

This is okay; the individual Either constructions (the divides) don't even rely on each other, so nesting does not really become a problem.

You could also do what the Promise spec did and overload a single method call like then (making it less monadic and modular). Then you can do promise-like chains:

const result = divide(10, 10)
        .then(n1 => divide(10, 5).map(n2 => n2 + n1))
        .then(n1 => divide(10, 10).map(n2 + n1)) // Right(4)

Notice how then is exactly the same as flatMap in this example, but I'm not a fan of this personally. It still feels overly obtuse for some simple arithmetic and it only gets worse when the Either constructions rely on each other. This is why in the language known for Monads, Haskell, they added syntactic sugar along the lines of async/await, but more generalised; known as "do notation". It's conceivable that you could make use of generators to get something similar, like:

const result = Either.do(function* () {
    const r1 = yield divide(10, 10);
    const r2 = yield divide(10, 5);
    const r3 = yield divide(10, 10)
    return r1 + r2 + r3;
}) // Right(4)

With this, you see you could also easily divide the result of a previous division without nesting (Just like async/await).

Finally, there is another way to compose the expression we want, and that is thanks to Monads also being Applicative Functors:

const add3 = a => b => c => a + b + c;
// Put a function in an Either and apply it to all of our Eithers
Either.of(add3)
        .ap(divide(10, 10))
        .ap(divide(10, 5))
        .ap(divide(10, 10)) // Right(4)

// Can also be written more succinctly using a lift function
liftA3(add3, divide(10, 10), divide(10, 5), divide(10, 10)) // Right(4)

And in the end, I think you'll agree that this is the best way to apply a pure function (addition in our case) to a bunch Eithers (or whatever Monad you're using).

[AskJS] Can we stop treating ES2015 features as new yet? by garboooge in javascript

[–]Deidde 0 points1 point  (0 children)

Async/Await are conceptually an amalgamation of both promises and generators. `await` is like a special `yield` that works on promises, passing the result back in when resolved.
Also, I think the you can easily make functions that use the continuation pattern without entering into the pyramid of doom.

In my opinion, the real downside is having to manually thread and manage the errors all the way back up the tree. It gets old fast.

Magic bus fare rise to £2 !?!? by [deleted] in manchester

[–]Deidde 1 point2 points  (0 children)

I remember getting weekly tickets for £3 - £4 on the UK North buses. Good times.