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
xtal
Jan 9, 2011

by Fluffdaddy
If you think the web is good enough I don't even know where to begin with that.

Adbot
ADBOT LOVES YOU

EmmyOk
Aug 11, 2013

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.

a witch
Jan 12, 2017

the talent deficit posted:

i think it's only a matter of time before you see clients that effectively just make rpc calls to a backend service. whether this is negotiated via an sdk that uses graphql/rest or just uses something like gRPC or thrift over http2 i think application developers will stop having to care about the details of how their app talks to the server

Unless I'm missing something, isn't this just J2EE thick clients from 2 decades ago?

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



xtal posted:

If you think the web is good enough I don't even know where to begin with that.

If you're doing something a browser can't do well enough for 99% of users then yeah sure it's real bad. Otherwise, it's a featureful, near-universal UI toolkit that, like any other complicated thing, happens to have some sharp edges and only runs a janky-assed language under the hood that you never have to write a line of if you don't want to.

Also many people misuse the poo poo out of it in various terrible ways, so there's that.

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

EmmyOk
Aug 11, 2013

baka kaba posted:

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

I've been bouncing around between it, my book, and googling particular things. I tend to end up on the site a lot though because it's such a great resource, for example it's the first place that went through what function signatures actually mean. At the moment it's really weird getting my head around using recursion to replace loops. Or I'll see a short code segment and spend a few hours trying to work out how it actually works.

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!

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
Ok where do I get all of your neat editor things in VS2015? ^^^ those are some hot digraphs

F# for Fun and Profit is a great resource. The author of it somehow knows exactly what he can assume I already know, and then also what I want to know about F# as it relates to what I need to know .. if that was understandable ... he's good at instructional writing is what I mean.

EmmyOk posted:

At the moment it's really weird getting my head around using recursion to replace loops. Or I'll see a short code segment and spend a few hours trying to work out how it actually works.

I've written forth for a few things, and I feel like I became an able F# programmer once I realized that I am more or less writing backwards forth.

When I think about looping in a functional language, I think about lists. When I want a loop in an imperative program, I'm trying to apply a function or repeat a procedure until some condition breaks the loop. In F# this is usually just the end of the list you're working on.

I haven't had really any guidelines to go by. I don't know if I'm right or standard about anything, criticism is welcome, but with F# I take this approach:
- Arrange data into one or more fancy union type trees.
- Get my data into lists of whatever type.
- Parse the list using the hella sweet list matching, and maybe have some side-effects.
- Repeat ad absurdum.

Maybe it was because I learned F# to parse things (fparsec is soo good uuh), but I feel that with F#, with thanks to the type system and matching, everything can be approached as a parsing problem w/ side effects (is this what haskell users have been doing? wow whoa). I never use the built-in list operators in lieu of using recursive matching, because it's always clear to me what is going on in my program that way. I can break down every god drat branch my program makes if I please. My F# programs are all a series of 'type', 'let'/'let rec', 'and', 'do', with the occasional lazy keyword.

When you use recursion, you are literally creating a list; This is either as a transform of the list/tree of data you're working on, or you are generating a new list. Each called function appends its context or value after the callee's context, more or less. When the last call hits the condition that "breaks the loop", you have the choice of returning some aggregate value, or unrolling that chain of calls and returning a list.

I'm not much of a Java programmer, I think IIterable is the name of the interface in Java, but it's nearly the same (I don't think it's evaluated the same) approach as using C# IEnumerable, the Enumerable class methods, and the yield keyword, if that is helpful.

And of course, since lists and functions are first-class types, which can hold types of themselves as values, the purpose of your program is to cull the state of these things into a self-parsing well-trimmed n-ary tree that has the function you wanted.

I think that the 'trick', so to speak, is to treat your program like a stack of typed values/functions/lists, and to operate on that stack like you're making a little stack machine. By Currying, the only operation of this machine is to create one big function that will eventually be evaluated when you ask it nicely and feed it some data in the right order.

So really, instead of trying to cram all that typing info into your face, and remembering what level of indirection you've stumbled into, you only focus on the immediate area. The words, "I saw the angel in the marble and carved until I set him free" come to mind. Your job as an F# programmer is to cull state. In this awfully melodramatic analogy, the data is the marble and F# is your chisel. You just gotta chisel that data bit by bit until a statue comes out.

I'm not the best functional programmer; I'm going to have to be buried with a C compiler if my brain hasn't turned into one by then, but I've done some fancy low-level research/work on the topic ... I can go on but I'm a really terrible technical writer I think, and I'm not sure what I can speak openly about, but I think I can try to help fellow newbie F# programmers ...

dougdrums fucked around with this message at 22:54 on Jan 20, 2017

Ochowie
Nov 9, 2007

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

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

Mr Shiny Pants
Nov 12, 2012
What I love about F#: If it compiles, it usually runs flawlessly.

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

baka kaba posted:

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:

The code lens (automatic type annotations) in Ionide is amazing. I think it's the first feature it offers that simply can't be found in Visual Studio, and makes it a legit alternative even if you're running on Windows.

I still went back to VS because managing project files by hand (or with Forge's extremely limited commands) is godawful, and the .NET Standard thing has only made targeting even more of a clusterfuck.

I do use VS Code for writing .fsx scripts, though. I made a batteries-included folder that contains FSI.exe and all its required libraries, so I can just give scripts to colleagues without needing them to have anything installed.

NihilCredo fucked around with this message at 10:24 on Jan 21, 2017

EmmyOk
Aug 11, 2013


This actually helps quite a bit! The first problem I looked at was the first Project Euler question (sum of 3s and 5s below 1000) and at first I was thinking of how to start at 1000 and step back in steps of 5 and 3. After a few minutes I realised I was thinking about it all wrong and just filled a list and filtered it followed by sum. The bit of code I am failing to understand currently is the following
code:
let listOfList = [[2; 3; 5;]; [7; 11; 13]; [17; 19; 23; 29]]

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

printfn "%A" primes
This prints a single list composed of all those numbers. it's the |head... line that is confusing me. If it's just pulling off the first list will you not just keep re-adding full lists to a list of lists?

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

It picks out the head, which is a list, and glues that onto the result of recursing on the tail of the list of lists.
You basically end up with

code:
[2; 3; 5;] @ [7; 11; 13] @ [17; 19; 23; 29] @ []

EmmyOk
Aug 11, 2013

Su-Su-Sudoko posted:

It picks out the head, which is a list, and glues that onto the result of recursing on the tail of the list of lists.
You basically end up with

code:
[2; 3; 5;] @ [7; 11; 13] @ [17; 19; 23; 29] @ []

Oh my god I am so dumb it just clicked. Shameful.

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

Hehe I think it's a pretty common problem! I certainly struggled with it when I was learning this stuff :)

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

NihilCredo posted:

The code lens (automatic type annotations) in Ionide is amazing. I think it's the first feature it offers that simply can't be found in Visual Studio, and makes it a legit alternative even if you're running on Windows.
I still went back to VS because managing project files by hand (or with Forge's extremely limited commands) is godawful, and the .NET Standard thing has only made targeting even more of a clusterfuck.
I do use VS Code for writing .fsx scripts, though. I made a batteries-included folder that contains FSI.exe and all its required libraries, so I can just give scripts to colleagues without needing them to have anything installed.
All of the digraphs don't show up in VS2015, or I least I couldn't get them to ... in Code they work great though! I've been using Code on my linux laptop, for working on the run or when I'm waiting somewhere. It makes good use of screen space when I don't need a debugger or I am content with using gdb manually. Someone I work with made a more-or-less makefile using a fsx script, including building C libraries. It worked well and I thought it was a pretty good idea.

I find codelens to be annoying in VS (only because it messes up the spacing), but I do find myself hovering my mouse over definitions quite often ...

dougdrums fucked around with this message at 16:21 on Jan 21, 2017

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

dougdrums posted:

All of the digraphs don't show up in VS2015, or I least I couldn't get them to ... in Code they work great though! I've been using Code on my linux laptop, for working on the run or when I'm waiting somewhere. It makes good use of screen space when I don't need a debugger or I am content with using gdb manually. Someone I work with made a more-or-less makefile using a fsx script, including building C libraries. It worked well and I thought it was a pretty good idea.

I find codelens to be annoying in VS (only because it messes up the spacing), but I do find myself hovering my mouse over definitions quite often ...

The ligatures involving a hyphen "-" (which unfortunately is most of them) don't work in Visual Studio due to some issue with its codebase, and I don't expect it to be fixed either; others do work, but since those ligatures are Fira Code's entire selling point, I just use a different font for VS (Office Code Pro Medium, if you're curious).

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!

EmmyOk
Aug 11, 2013

Reading on in the book they are dealing with for loops and sequences but I'm planning to avoid for loops of any description because they're not functional right? And that does help, baka!

Mr Shiny Pants
Nov 12, 2012

EmmyOk posted:

Reading on in the book they are dealing with for loops and sequences but I'm planning to avoid for loops of any description because they're not functional right? And that does help, baka!

Meh, if it works it works. Don't get hung up on it, if it easier to understand use it.

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

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Mr Shiny Pants posted:

Of the top of my head, the guy was talking about how you would implement a webserver in Erlang and instead of one process that handles the connections and kicks of threads you would have a process for every connection coming into the server.

Not in particular, no. I was just wondering about general guidelines.

I saw your talk, supervision trees look really nice.

Joe Armstrong wrote a thing at one point?
http://joearms.github.io/2016/03/13/Managing-two-million-webservers.html

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I realize this is pretty vague but for those who use Haskell, what type of projects have you used it for? I'm making another try at wrapping my head around functional programming with Haskell and looking for inspiration on some projects that people have use the language for. Outside of large, enterprise-size applications.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today
My two most recent Haskell projects were a geospatial webapp for a hackathon at work, and little GUI utility to implement the Schulze voting method (lesson learned: never, ever try to write a portable GUI by using GTK in any language).

sink
Sep 10, 2005

gerby gerb gerb in my mouf
I am writing Diplomacy (the board game) as a REST service which I will turn into a Slack bot. I've used it for a few other random small services.

I have no loving clue what Australia uses it for, but here's the job post: https://jobs.csiro.au/job/Brisbane%2C-QLD-Functional-Programming-Engineers/385668100/

Galois in Portland, Oregon, US uses it for space stuff. Or maybe crypto stuff. Or maybe crypto in space stuff. https://galois.com/careers/software-engineer/

Its ecosystem is good enough to use it as a general purpose programming language, but for some applications it is pretty obtuse.

sink fucked around with this message at 04:42 on Feb 2, 2017

Bongo Bill
Jan 17, 2012

Facebook uses it in production but I don't know to do what specifically.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
They wrote Haxl, a library for remote data retrieval (like SQL, I suppose?) Haskell is pretty good for server-side web-based stuff like APIs. Also parsing and language design.

sink
Sep 10, 2005

gerby gerb gerb in my mouf
FB also uses it for spam, and hired Brian O'Sullivan and some other big-name Haskell people. Many talks online about Haskell at Facebook and how to train an engineering team in FP.

As a side note, they also use OCaml and built a new and somewhat disappointing-looking language on top of it.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture





Hughmoris posted:

I realize this is pretty vague but for those who use Haskell, what type of projects have you used it for? I'm making another try at wrapping my head around functional programming with Haskell and looking for inspiration on some projects that people have use the language for. Outside of large, enterprise-size applications.

i wrote an interpreter for a dumb programming language i invented

gonadic io
Feb 16, 2011

>>=

the talent deficit posted:

i wrote an interpreter for a dumb programming language i invented

Including coursework, I've written a compiler, a physics engine, a program to generate a depth map from stereoscopic images, and then a bunch of algo stuff and puzzles.

Never done any web/networking stuff myself in it.

my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine
I'm looking at Idris.

Can anyone shed some light on what's going on here:
code:
data Fin : Nat -> Type where
   FZ : Fin (S k)
   FS : Fin k -> Fin (S k)
I think I understand what Fin 5 represents, but what's going on with these constructors??

xtal
Jan 9, 2011

by Fluffdaddy

Ploft-shell crab posted:

I'm looking at Idris.

Can anyone shed some light on what's going on here:
code:
data Fin : Nat -> Type where
   FZ : Fin (S k)
   FS : Fin k -> Fin (S k)
I think I understand what Fin 5 represents, but what's going on with these constructors??

Do you notice a similarity between that type and the linked list? It's numbers represented at the type level by recursion. A function like 'length' on link lists could convert this type to an integer.

Asymmetrikon
Oct 30, 2009

I believe you're a big dork!
Fin n represents a finite set of size n (where n is greater than 0) - so like the natural numbers, but bounded by n.

FZ is the zero element, which is a member of all finite sets. You can think of its constructor as "for all natural numbers n, FZ is a member of Fin n iff n is greater than zero".

FS is the successor function; pretty much the same as the Nat successor.

Probably a point of confusion is that FZ and FS can inhabit multiple different types. FZ is a member of Fin 1, Fin 2, and so on. The finite sets are generated inductively, so Fin (S n) contains all of the elements of Fin n, plus FS applied on the greatest element. If we look at the members of each of the Fin instances, we see:

Fin 0 {}
Fin 1 {FZ}
Fin 2 {FZ, FS FZ}
Fin 3 {FZ, FS FZ, FS FS FZ}
...

So (FS FS FS FZ) is a member of Fins 4+.

Ralith
Jan 12, 2011

I see a ship in the harbor
I can and shall obey
But if it wasn't for your misfortune
I'd be a heavenly person today

Ploft-shell crab posted:

I'm looking at Idris.

Can anyone shed some light on what's going on here:
code:
data Fin : Nat -> Type where
   FZ : Fin (S k)
   FS : Fin k -> Fin (S k)
I think I understand what Fin 5 represents, but what's going on with these constructors??
Remember that k : Nat is implicitly universally quantified, because it's lower case. Read the constructors as "for all Nats k, FZ inhabits Fin (S k)" and "for all Nats k, applying FS to a Fin k produces a Fin (S k)"

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
I want to look into erlang or elixir for web development, after having a lot of experience with Python. My main usage will be building stuff bigger than the stuff I use Django for, so essentially I want to figure out the OTP stuff so I can make good use of the hardware I have with at least security in the knowledge that scaling won't be so bad as splitting up a monolith.

What's best in breed in the ecosystem according to people who actually use erlang/elixir? What am I losing if I use elixir? All the frameworks out there market themselves exactly the same way saying they have a great dev experience or fault tolerant or whatever, all products of the language largely, so it's hard to tell where's the best place to invest my time in first.

Arcsech
Aug 5, 2008

Maluco Marinero posted:

I want to look into erlang or elixir for web development, after having a lot of experience with Python. My main usage will be building stuff bigger than the stuff I use Django for, so essentially I want to figure out the OTP stuff so I can make good use of the hardware I have with at least security in the knowledge that scaling won't be so bad as splitting up a monolith.

What's best in breed in the ecosystem according to people who actually use erlang/elixir? What am I losing if I use elixir? All the frameworks out there market themselves exactly the same way saying they have a great dev experience or fault tolerant or whatever, all products of the language largely, so it's hard to tell where's the best place to invest my time in first.

If you want to do web dev in the Erlang ecosystem, Elixir + Phoenix is almost certainly what you want, especially coming from Python. Phoenix is very user-friendly, and it's far and away got the most users and the largest community of anything on the BEAM (Erlang VM).

Programming Elixir and Programming Phoenix are both pretty good books to get started with Elixir.

The downsides of using Elixir rather than Erlang:
  • The Elixir syntax makes it feel more like your old programming language, which can make it tempting to write non-Erlangy code
  • You will want to learn to read Erlang syntax at some point anyway, because a lot of the examples on the internet are written in Erlang (all of them are still 100% relevant to Elixir though)
  • Macro overuse is a thing people warn about, but I haven't run into problems (yet)

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Already looking through Monoqnc's book on erlang, so no doubt I'll be getting used to both syntaxes while I work through it, just not the type of person with the time or inclination to slowly work through an entire book, I'd rather be applying the knowledge to a project and jumping back and forth between learning and doing. I guess Phoenix is where to carry on with that.

my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine

Ralith posted:

Remember that k : Nat is implicitly universally quantified, because it's lower case. Read the constructors as "for all Nats k, FZ inhabits Fin (S k)" and "for all Nats k, applying FS to a Fin k produces a Fin (S k)"


Asymmetrikon posted:

Fin n represents a finite set of size n (where n is greater than 0) - so like the natural numbers, but bounded by n.

FZ is the zero element, which is a member of all finite sets. You can think of its constructor as "for all natural numbers n, FZ is a member of Fin n iff n is greater than zero".

FS is the successor function; pretty much the same as the Nat successor.

Probably a point of confusion is that FZ and FS can inhabit multiple different types. FZ is a member of Fin 1, Fin 2, and so on. The finite sets are generated inductively, so Fin (S n) contains all of the elements of Fin n, plus FS applied on the greatest element. If we look at the members of each of the Fin instances, we see:

Fin 0 {}
Fin 1 {FZ}
Fin 2 {FZ, FS FZ}
Fin 3 {FZ, FS FZ, FS FS FZ}
...

So (FS FS FS FZ) is a member of Fins 4+.


xtal posted:

Do you notice a similarity between that type and the linked list? It's numbers represented at the type level by recursion. A function like 'length' on link lists could convert this type to an integer.

These were all pretty insightful, thanks!

Adbot
ADBOT LOVES YOU

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


I've been asked to give a talk introducing Haskell and functional programming to a group of fairly experienced C++ developers. I can go through a pretty standard introduction covering the various languages out there, the way expressions are evaluated model, the idea of formal semantics, and the major language features, but I'm wondering if there's anything that's specifically helpful for people whose primary experience is a with a low-level stateful imperative language. I've found the Haskell Tutorial for C Programmers and I'm going to read through that, but I'd really appreciate anything else that might be helpful.

  • Locked thread