Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

EmmyOk posted:

I'm going through old problems that were a breeze in OOP and taking ages to work out how to even approach them functionally. It's tremendous fun though, I'm being pushed hard to work out how to do things from scratch again.

Get ready, it's gonna ruin Java for you!

If you haven't seen it already you should take a look at F# for fun and profit, it's really comprehensive - and a lot of the examples give you an imperative approach in C#, then the F# equivalent, and then refine it into a more natural F# approach. You can pick up a lot from that kind of thing

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Yeah my issue is knowing how compact functions can be once you combine the right ones to process your data, and then you end up thinking about your data structures much more abstractly. So then you end up trying to mentally juggle this idea of working on lists of lists of tuples or whatever, and my brain isn't ready for that. Good exercise though, I get there eventually

You're using something that annotates your function signatures as you work on them, right? That's a huge help for checking what it knows you're putting in and what it spits out, you can make changes and see the result immediately in your editor

Good for tweaking things until you actually get what you wanted

But yeah there's a few people in here who know F# on some level if you want to throw anything out there!

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

dougdrums posted:

Ok where do I get all of your neat editor things in VS2015? ^^^ those are some hot digraphs

Oh yeah, totally forgot about that - it's just the Fira Code font, it has nice ligatures. I use VS Code with the Ionide plugins mostly, it's nice for quick scripting - plus I feel like I'm learning more of the nuts and bolts of working with . NET projects than with VS 2015 :frogbon:

Ochowie posted:

On the topic of f# and monads (this being the FP thread) I stumbled on this tutorial for working with monads in f#.

If you're interested there's one here too
https://fsharpforfunandprofit.com/posts/computation-expressions-intro/
It's more of a series so it's a bit longer, but it feels more like a general introduction to the concepts and why you'd use them. I'm a nublet so I need the hand-holding

baka kaba fucked around with this message at 00:10 on Jan 21, 2017

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I just realised the -> ligature isn't working in VS Code for F#, but it was before and it works fine if the language mode is set to Plain Text :ohdear: weird

So it's called a code lens huh. I thought there was something similar in F# Power Tools, but I guess not! Anyway it's rad as hell, the spacing bothered me at first and then I realised I didn't really care. A toggle would be cool though


EmmyOk posted:

code:
let rec concatList l =
    match l with
    | head :: tail -> head @ (concatList tail)
    |[] -> []

This is just One Weird Trick, but when your function (concatList) has one parameter and you jump straight into pattern matching on it, you can rewrite it as
code:
let rec concatList =
    function
    | head :: tail -> head @ (concatList tail)
    | [] -> []
which is basically saying 'whatever I pass into this function, do this pattern match on it'. (It's not as limited as that, but this 'one parameter function' thing is a common scenario). Down to personal choice and the situation whether you use it or you want an explicit named parameter, but it's an option

And if that's confusing then don't worry about it right now!

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

This is sort of the problem I have with it - there's like (broadly) OOP, imperative programming and functional programming, and you can mix and match to achieve the same ends in different ways, and a lot of books and tutorials dive into everything instead of deciding on one best practice and showing you how to work within that paradigm. F# especially seems to encourage this because it sits in a weird place between pure functional languages and the rest of .NET, which it can interoperate with. I mean look at this:
https://fsharpforfunandprofit.com/posts/13-ways-of-looking-at-a-turtle/
Some of that is different approaches to designing the system, but others are like 'here you can use classes' or 'here you can use record types'. You have a lot of freedom, and it can make it easier to learn when some of it is familiar OOP style, but it can make it hard to learn to make the right decisions when you want to tackle a problem in a certain way, you can end up straying in the wrong direction

Anyway yeah it's sort of an imperative vs declarative thing, the idea is that functional languages (and stuff like LINQ in C#) allow you to describe what you want to happen to the data, instead of doing all the manipulation by hand, possibly using mutable state while you juggle things and build a result. Functions like map and fold can transform data and produce a final result just by describing what you want to happen. Getting familiar with that stuff will make it easier to work with, and you'll be able to create and compose complicated workflows with not a lot of code

This stuff might help! Yes that site again

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Anyone know enough about F# scripting to help with this?

I've separated a small project out into three .fsx files to keep things organised. The first calls a function in the second, and they both refer to a union type from the third. I'm getting this fun error when I try to run the first file

code:
The type 'FSI_0002.Polls.Party' does not match the type 'FSI_0003.Polls.Party'
Both files do #load "Polls.fsx" and open Polls. Party is just a simple union type at the top of the file. They're both referencing the same thing, there's no circular dependency. How are they not the same type? The Code Lens thing in Ionide is totally fine with it too.

I'm guessing the different FSI_000x stuff is an issue, like they're in different scopes or something? I actually did get it to run when I poked at something (going from a record type using Party to a tuple with one) and thought that fixed it, but now it's decided there's a problem again. I have no idea what's going on, and I'm guessing it's something really simple, but :confused:

code:
error FS0001: This expression was expected to have type
    FSI_0019.Polls.Party
but here has type
    FSI_0020.Polls.Party
:negative: why


e- urgh looks like it's a limitation with script files. I thought it would merge into one file but apparently it's generating separate assemblies, and that's why the magic namespaces are there. Back to full-on projects I guess!

baka kaba fucked around with this message at 08:19 on Feb 17, 2017

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Weird, I thought I already tried that. Maybe that's what made it work once and I just didn't realise. Thanks!

So I guess a script file can only open modules from files it loads directly, or from any files those files load, and so on? So in the end it's sort of recursively building up one large fsx file? And any code that relies on something 'higher up' has to either load that module itself, or something earlier has to have done it, and not both?

I'm used to the single file way of doing things, not so much splitting them up. If I want to remove this coupling, so that file2 can access the types in file3 whether it opens file1 or not, am I looking at compiling assemblies in a full project, so the loading's taken care separately of and I can just open modules directly?

Lots of ?s in there

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Yeah I'm just trying to get my head around what's happening. Like if you define a type twice in a single file, you get an error, but you can load it twice and it creates two separate types with the same name, the second shadowing the first.

I think I assumed running the same definition code would either give a duplicate definition error or silently overwrite the value of the globally visible type, but I guess that doesn't make sense for an interpreted script huh

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Like Asymmetrikon's saying, I guess you want something like this?

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I made one in F# (that was probably bad) that basically created a sequence of tokens, used windowed and map to create pairs in tuples, and then folded those into an empty Map. The folding function looked up Token1 in the map, which returned another map of all the following tokens and their counts. Then it checked that for Token2 and either incremented its count or added it as a new entry. Then after the fold it did a map converting all those counts to normalised weights

You could use a mutable Dictionary too but I was trying to be :pcgaming:functional as hell:pcgaming:

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

In this case I don't think using a Map over a Dictionary is that much of a change, from a coding perspective at least. It's not like Array2D hell or anything. Try it out!

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Oh nice - brand new in... 2.0? :catstare:

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I definitely haven't done anything like that before, heheheeeeeeh

Sometimes it's good to just type something like Option and see what functions it exposes, there's a lot of useful stuff just waiting for you to implement yourself like a caveman leverage elegantly. I wish Microsoft's documentation site wasn't dog slow because you could learn a lot casually browsing that too

Adbot
ADBOT LOVES YOU

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

F# for fun and profit is always the go-to - it has a basic tutorial path but there's a ton of content in there

  • Locked thread