|
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
|
# ¿ Jan 20, 2017 19:48 |
|
|
# ¿ May 14, 2024 21:07 |
|
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!
|
# ¿ Jan 20, 2017 20:33 |
|
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 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 |
# ¿ Jan 20, 2017 23:46 |
|
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 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:
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:
And if that's confusing then don't worry about it right now!
|
# ¿ Jan 21, 2017 17:57 |
|
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
|
# ¿ Jan 23, 2017 19:10 |
|
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:
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 code:
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 |
# ¿ Feb 17, 2017 07:29 |
|
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
|
# ¿ Feb 17, 2017 18:53 |
|
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
|
# ¿ Feb 18, 2017 20:18 |
|
Like Asymmetrikon's saying, I guess you want something like this?
|
# ¿ Mar 23, 2017 16:24 |
|
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 functional as hell
|
# ¿ Mar 25, 2017 19:25 |
|
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!
|
# ¿ Mar 25, 2017 21:49 |
|
Oh nice - brand new in... 2.0?
|
# ¿ Mar 28, 2017 21:40 |
|
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
|
# ¿ Mar 29, 2017 19:38 |
|
|
# ¿ May 14, 2024 21:07 |
|
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
|
# ¿ Jul 15, 2017 20:47 |