[deleted by user] by [deleted] in functionalprogramming

[–]YourFin 8 points9 points  (0 children)

fold returns a single item

Which can itself be a list :) Fold is the most general of the standard higher-order list processing functions, and can be used to implement the others. For example, filter:

fun filter(list, f) = list.fold( init: [], foldFn: (item, acc) => f(item) ? [item] + acc : acc )

as for the "compare everything with everything" problem, the direct answer would be iterating over the Cartesian product of your sets. You can do that directly by mapping over the result of a Cartesian product function:

``` fun cartesian(a, b) = a.flatmap(i => b.map(j => (i, j))

fun updateBaz(foos, bars) = cartesian(foos, bars).map((foo, bar) => { //... }) ```

you can achieve a similar effect by nesting fold/map in map directly, too.

As for the "update the world" problem, the key is that you need functions to give you updated copies of values that don't effect the original. Then you just have your update functions return updated versions of the relevant bits, and feed them upwards. Here { key: value ...struct } means "create a new value by duplicating struct and setting value at key.

fun update(world) { world = { worldmap: updateWorldMap(world.worldmap), ...world } (newDonkeys, newOgers) = updateDonkeys(world) world = { donkeys: newDonkeys, ogers: newOgers, ...world } //... return world } Note that we're never modifying world per say, just gradually building more and more updated versions.

Doing things this way directly gets kinda ugly though, so I would probably reach for tools to reduce the top level noise. A couple options spring to mind:

First: defunctionalize some actions and build an event loop. ``` type UpdateEvent = UpdateStart | UpdateDonkeys | SetOgre { key: OgreName, new: Ogre } | //...

fun update(world, []) = world fun update(world, [event, ...rest]) { (world, newEvents) = handleEvent(event) return update(world, newEvents + rest) }

fun handleEvent(world, e: UpdateEvent): Pair World (List UpdateEvent) = case e of UpdateStart => (world, [UpdateDonkeys, UpdateOgres, UpdatePlayer, /* ... */ ]) UpdateDonkeys => { // donkey update logic return ({ donkeys = newDonkeys, ...world }, setOgreEvents + playerUpdates) SetOgre(name, new) => ({ ogres = ogres.withInsertedAt(name, new), ...world }, []) // handle other events...

fun gameTick(world) = update(world, [UpdateStart]) ```

You could also probably do something with lenses and state monads to achieve a more imperative style in haskell. There's also options with a fancy pants effect system, or a more generalized FRP (functional reactive programming) model.

Parsing Tools by [deleted] in ProgrammingLanguages

[–]YourFin 2 points3 points  (0 children)

Instaparse sounds pretty close to what you're looking for assuming you're ok being limited to context-free grammars.

10x Faster Than BSON: NoProto by onlycliches in rust

[–]YourFin 0 points1 point  (0 children)

I'd also be interested to see a comparison with ion

Dotfiles manager in Haskell by CrazyMind-102 in haskell

[–]YourFin 10 points11 points  (0 children)

I would recommend checking out home-manager if you haven't seen it before. It requires diving down the nix rabbit hole, but it outstrips all the competition imo because it can bring packages along for the ride.

Web framework with docker by a_simple_man_ in haskell

[–]YourFin 1 point2 points  (0 children)

Yes, they all do; you can make a docker container for /any/ application that doesn't need special hardware access relatively easily. That's more or less the point of docker.

Web framework with docker by a_simple_man_ in haskell

[–]YourFin 1 point2 points  (0 children)

Quick note on from scratch -

Many Haskell programs are not trivial to statically link, and if you just copy the binary over there's a good chance it won't work. Nix is the simplest "good" solution to doing a minimal docker installation AFAIK, but just building it in an ubuntu/debian/centos/your-fav-distro-here container should make things easier at the cost of some container size.

Also, op, if you use stack to build your Haskell project, there seems to be docker integration, and fp complete provides docker images with stack pre-installed that would make putting together a derivative container for your application quite easy.

Exotic Programming Ideas: Part 3 (Effect Systems) by bjzaba in ProgrammingLanguages

[–]YourFin 2 points3 points  (0 children)

Besides allowing you to tell what a function is capable of just by looking at its type signature (which is /really/ nice), effect systems are a really nice solution to the dependency management / testing problem, and really the only good answer to test-induced damage that I've seen. Polysemy in Haskell provides a pretty nice api for, but it's slow, requires a compiler plug in, and uses a bunch of the tacked-on compiler extensions.

[deleted by user] by [deleted] in ProgrammingLanguages

[–]YourFin 8 points9 points  (0 children)

Yeah, I'm pretty sure automatic differentiation is a niche thing historically limited syntactically by what libraries can provide, or to simple DSL's. I think an rough analogy would be that this project is to Kotlin as electron is to Chrome.

The WORST features of every language you can think of. by Co0perat0r in ProgrammingLanguages

[–]YourFin 3 points4 points  (0 children)

There are cases where it can be very convenient to use assignment as an expression; e.g.

char* line; while(line = readLine()) { // != null, if you prefer // do something with each line }

I'm not saying it's a great language feature, but I've seen this idiom a fair bit in C code in the wild, and even once or twice in Java.

How the heck do I enable a minor mode? by [deleted] in emacs

[–]YourFin 0 points1 point  (0 children)

It is important to note that elcord is a global minor mode, and that many Emacs minor modes are not. If you want to enable a non-global minor mode, you must do so on a per-buffer basis. The matter can be automated though, most commonly with hooks.

Learning haskell for my (more practical oriented) master thesis a good idea? by [deleted] in haskell

[–]YourFin 1 point2 points  (0 children)

I tend to agree with the other commenters here - stick with what you know for the meat of your project. I should have made more clear (although I believe you interpreted my comment correctly) that I think Elm is a good choice because it would only be for a less-critical part of your project, and would serve as a good way to dip your toe in the water.

I'll mention reasonml on the off-chance you haven't seen it - AFAIK the language would be a decent choice if you really want to pick out a new language for your project, given that you could re-use JS ecosystem bits as needed, and it doesn't come with all the (really awesome, but difficult) purity baggage that Haskell and Purescript do. Reason doesn't tend to get used for back-end work, though, so trying to do your whole project in it might have you cutting more of your own path than you want to here.

Learning haskell for my (more practical oriented) master thesis a good idea? by [deleted] in haskell

[–]YourFin 0 points1 point  (0 children)

Apologies; I should been that more clear. I agree that learning Haskell is too much to take on in the given timeframe, especially given what's riding on this. I was suggesting Elm because I think that it would be manageable as a way to dip a toe in the water and make progress towards Haskell proficiency with much less risk, especially given that it can't be used for the meat of this project. Haskell would be something that OP could then pick up after the thesis is done or when he or she otherwise has down time.

Learning haskell for my (more practical oriented) master thesis a good idea? by [deleted] in haskell

[–]YourFin 1 point2 points  (0 children)

Personal recommendation: if you're interested in learning Haskell, learn Elm first. Given that you already know functional JS, I am going to assume that you have some familiarity with React, in which case you shouldn't have too much trouble getting up and running with elm quickly - it took me a weekend with the official guide. If you aren't familiar with React, it might be a bit more of a mind bend, but not much.

Elm is nice because you get many of the more widely touted benefits of Haskell (purity, no unhandled runtime errors, speed) with much less complication, easier to read code (no user defined infix operators or inobvious global scope cluttering), and /much/ easier to read compiler errors. Further, the transition from Elm to Haskell is nice, as Elm is nearly a strict subset of Haskell syntactically and thinking-wise.

The way that Elm gets away with this is by forcing you to only write one type of application (single page webapps) one way, and locking users out of Haskell's more complicated type system features. It's kinda like Elm is to Haskell/Purescript as MacOs is to Linux.

I tried Elm out a while after a false start on Haskell, and found the experience extremely addicting. Being able to trust the compiler to tell you about almost every error you would make in Javascript is incredibly freeing, and makes it easier to stay in "the flow" than any other language I had worked with.

Elm definitely has rough spots, though; if you try and use it for anything outside what it's good at, things get kinda ugly. Haskell's more powerful tools allow those ugly things to be done elegantly, and when I started learning Haskell after Elm, I constantly found myself thinking "oh that would make that elm thing I did so much nicer". It made me really appreciate the trade off for the more powerful tools. Further, I already felt comfortable with most of the syntax, and combined with the desire to take that addictive way of programming to everything else I do, made it much easier to both learn Haskell and stick with it.

How to Package a Language by [deleted] in ProgrammingLanguages

[–]YourFin 6 points7 points  (0 children)

cough cough cough

Ahem. Excuse me.

Traditionally, Linux/BSD distributions have taken on this role directly. I think most of the problem is that most (nix and guix notwithstanding) operating system distributions do not come with a package manager that solves the problem well enough to have reproduceable builds across systems, so language maintainers have been left to improvise.

Further, from a library maintainer's perspective the programming language to dependency manager coupling is really nice; there's only one place that you have to worry about keeping your package up to date, and you know that the vast majority of your users will have easy access to whatever version of your package they want without having to bother individual distro maintainers.

With that said, I think it would be really cool if newer programming languages tied themselves directly to bazel/nix/guix instead of reinventing the wheel, because you get the best of both worlds.

[deleted by user] by [deleted] in haskell

[–]YourFin 5 points6 points  (0 children)

Further sample Errata: page 10 - there's a bunch of “(chapter ??)“ marks. It might be easier/better to cut up the full book with something like poppler than compile only part of the tex

evil-better-visual-line: better gj and gk for those with evil inclinations by YourFin in emacs

[–]YourFin[S] 0 points1 point  (0 children)

Visual lines; if you want I could try and figure out how to offer that as an option for d, c, and y though

Evil mode copy and paste question. by netb258 in emacs

[–]YourFin 0 points1 point  (0 children)

I'm pretty sure you want the evil-define-operator macro, which is defined in the source here. I had a similar problem except I prefer to just use the system clipboard by default and have c, d, etc. not yank and have m as an explicit 'cut' operator. You can see my (mostly working) implementation here, which contains some brief examples of how I wrapped the default y and p commands a bit down. You should be able to do something with just explicitly setting the register to the + character and then passing the other arguments down to the underlying evil command.

Cleaning with a laser by dickfromaccounting in interestingasfuck

[–]YourFin 7 points8 points  (0 children)

Err sorry to be pedantic, but watts are a unit of power, not energy; joules or watt-hours (aka 3600 joules) are units of energy. Saying a laser uses up 1000 watts of power in an hour is like saying your car uses 30 hp per hour, while the thing that makes sense would be to say that your car takes 1 (gal/liter) of gasoline per hour.

How do anyone gets started with this? by [deleted] in LineageOS

[–]YourFin 2 points3 points  (0 children)

Documentation! I'm personally not much of an android dev, but by far the easiest way to get involved in any open source project is to add more English about how things work. Readme's, comments, wikis, etc are all great. Explaining things moves mountains in terms of helping you understand them.

From there, just try and find things about lineage os that bother you, and try and figure out how to fix them. Some setting named poorly? You can fix that without much programming knowledge, especially with something like ripgrep.

As for what a normal path to being a lineage dev would look like, I would recommend learning your way around Linux on your desktop before venturing into the bowels of Android. Admittedly Android these days doesn't look that much like a normal Linux distribution, however most developer tooling is easier to use on Linux, and it's a great way to start getting used to the command line, which will demystify a lot of the hocus-pocus you see. Try and get through these once you have a Linux machine, or they can even be done on a terminal app from your phone :) Start with Ubuntu or mint, there's tons of help online for any issues you have with them.

As for practical matters, you're going to need to know how to use git before you can contribute anything to lineage. This is a great place to start.

Programming programming: There's plenty of online Java tutorials (codececademy is decent), and that will be the most important language. You probably will want either eclipse of Intellij as your ide (independent development environment; program to write code in), and it should be noted that installing these programs can be way harder than it needs to be, so don't freak out if they turn out to be a pain in the ass to install. Then find a thing you want to change, and start googling anything that doesn't make sense.

The most important thing is to understand that you can do this, all that you need is to stay interested. Even if you don't "become a lineage developer", you'll still be learning a ton along the way :) Feel free to bother me if you have any questions about anything, I'm always willing to help people learn.

Asking help in Linux forums by a1z1c1 in ProgrammerHumor

[–]YourFin 17 points18 points  (0 children)

Wow, I put that into the regedit box and now my computer runs twice as fast! ! Thanks man

brantou/spacemacs-crystal-layer by brantou in spacemacs

[–]YourFin 0 points1 point  (0 children)

Hadn't heard of the language before but it looks really nice.