These are chat archives for rust-lang/rust

21st
Sep 2016
CodeTortoise
@CodeTortoise
Sep 21 2016 04:23
Hello people. I am at a crossroads. I started diving into Rust, but then I got the Haskell Programming From First Principles book.
Now I wonder if I should just do Haskell until that Jim Blandy books is complete. Any pointers to a good sequence for Rust?
Flavius Aspra
@flavius
Sep 21 2016 04:24
@CodeTortoise any other previous experience with programming languages?
CodeTortoise
@CodeTortoise
Sep 21 2016 04:25
@flavius C++, Clojure
C
Erlang for a moment.
Minimal Python and Ruby. Looked at Lua
Flavius Aspra
@flavius
Sep 21 2016 04:25
@CodeTortoise Then there's no reason not to learn both in parallel, haskell for your formal education, and rust for pragmatism
they go hand in hand anyway
I was thinking about starting to learn haskell properly also
CodeTortoise
@CodeTortoise
Sep 21 2016 04:26
Ah, I felt like I was going to end up doing that. Right, Rust has a similar Type System>
CodeTortoise
@CodeTortoise
Sep 21 2016 04:44
I ignored my laptop's plea for juice, and I let it die
Michael Howell
@notriddle
Sep 21 2016 05:41
Not only are they similar in some respects (mostly just enums and traits), but they're different enough that it makes sense to use both for different things. Rust would be an appropriate language to write the Haskell RTS in (it's currently written in C), for example.
fstuess
@fstuess
Sep 21 2016 08:05
@CodeTortoise @flavius (others?) I'm having some python background and did a lot of FORTH eons ago. Seems to be a standard scheme to learn rust and haskell since i am also trying to do this. Interested in sharing experience to climb the learning curve? would be off topic for this chat. so pls contact me on my profile.
CodeTortoise
@CodeTortoise
Sep 21 2016 15:45
@fstuess Truthfully, I only just begun climbing the learning curve on Rust, and I am restarting learning Haskell with an actually good resource... I haven't even set foot on the Haskell hill.
Jonathan Turner
@jonathandturner
Sep 21 2016 15:46
@CodeTortoise - curious to hear your thoughts as you climb the learning curve
doing everything I can to smoothe it out a bit :)
CodeTortoise
@CodeTortoise
Sep 21 2016 15:48
@fstuess Coincidentally, I read half-way through Starting Forth before getting distracted. I still plan to finish it. Compared to Forth, Rust and Haskell is are huge languages. There are many ways to accomplish your goals, but unlike Forth you don't really build the language from the ground up.
@jonathandturner I think what helps is having good resources to learn from when you get stuck. I am excited to get back to Haskell because there is a finally an amazing book to learning all the core concepts used in Haskell. Rust has great community on every forum, and the though the documentation is still maturing, it explains its hard concepts like lifetimes, ownership, and borrowing very well.
CodeTortoise
@CodeTortoise
Sep 21 2016 15:54
The point is that the learning curve just got a whole lot gentler for me, at least with Haskell. Rust is still new to everyone, and it changes, so what helps is just to experiment and do projects, and building a good understanding on how things work.
exercism.io and hackerrank are our friends.
Jonathan Turner
@jonathandturner
Sep 21 2016 15:56
hadn't heard of hackerrank before...
@CodeTortoise - the learning curve for Haskell got gentler just because of exposure with it over time?
CodeTortoise
@CodeTortoise
Sep 21 2016 16:00
@jonathandturner What I mean is, even if you are new to Haskell, or even programming, the language has gotten so much easier to learn. There are better resources, Stack exists and is replacing Cabal.
However, learning Rust will be a matter of exposure and time.
LeonineKing1199
@LeonineKing1199
Sep 21 2016 16:12
Speaking of Haskell, I've heard people call Rust a functional language before. Why would they say that?
Jonathan Turner
@jonathandturner
Sep 21 2016 16:15
@LeonineKing1199 - it uses closures and composition in a way that's indicative of FP
but it's probably better to call it multiparadigm
Jonas Platte
@jplatte
Sep 21 2016 16:16
if you want to go technical, you could call any language where functions types are built into the type system functional. the special things about haskell, purescript, agda, idris and the like isn't being functional but being purely functional.
Perl, JS, Python, Lisp, Erlang and many more are functional as well. They're just also imperative, and don't distinguish between effectful and non-effectful computations / functions (which is what purity is about).
Actually I'm not 100% sure all of them are also imperative, Erlang might not be, and for Lisp it's hard to say with so many dialects
But pretty sure they're all non-pure (just like rust)
Jonathan Turner
@jonathandturner
Sep 21 2016 16:20
calling something "pure" is great marketing. I mean, who wants to be impure?
LeonineKing1199
@LeonineKing1199
Sep 21 2016 16:23
I was gonna say, Rust isn't functional to me because you can't enforce referential transparency at a language level.
D has the pure keyword though which actually does that.
I'd say Rust has functional features but calling it a functional language is... weird.
I put Rust into the same classification as C++, but that's my opinion.
Jonathan Turner
@jonathandturner
Sep 21 2016 16:25
imho, multiparadigm is a handy middle ground. it lets you switch styles to what fits a problem best
LeonineKing1199
@LeonineKing1199
Sep 21 2016 16:25
Oh dude, imperative and functional code mixed together is like the best thing ever.
I'm not super into OO code so I don't use it much
But, man, you mix some functional approaches with imperative code and damn, it's pretty great.
I've actually been reading the Gentle Introduction to Haskell and it's a great read.
It feels like it's targetted at C programmers.
The language, though, is something that you really, really can't fake.
I've seen a lot of JS libraries that try to be Haskell but you just can't. Haskell is as Haskell is.
Michael Howell
@notriddle
Sep 21 2016 17:05
haskell(x) = haskell(x), no matter how haskell is defined.
Jarred Nicholls
@jnicholls
Sep 21 2016 19:21
Is this a bug, not being able to implement an Index<MyType> as a blanket implementation on all slices? https://is.gd/KDBZHs
I've tried a few variations (implementing T bounded by Index<usize> for example)
Also went the brute force route and implement for each [SomeType] instead of generic [T]
(which works of course)
CodeTortoise
@CodeTortoise
Sep 21 2016 19:36
@jonathandturner @LeonineKing1199 "Pure" merely means that the language is semantically equivalent to the lambda calculus
Jonathan Turner
@jonathandturner
Sep 21 2016 19:38
@CodeTortoise that's an interesting definition
I've always heard "free of side-effects"
CodeTortoise
@CodeTortoise
Sep 21 2016 19:40
Rust is a functional language. It evaluates expressions. Those expressions can be applied to an argument or value, and expressions can be reduced or evaluated.
Jonathan Turner
@jonathandturner
Sep 21 2016 19:40
@CodeTortoise - see above :)
CodeTortoise
@CodeTortoise
Sep 21 2016 19:41
Free of side-effects is also meant by "purity"
Jonathan Turner
@jonathandturner
Sep 21 2016 19:41
I'm still thinking about your lambda calculus definition
I can squint and see it, but in practice you don't want this as an ability
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:42

Rust is a functional language. It evaluates expressions. Those expressions can be applied to an argument or value, and expressions can be reduced or evaluated.

This is generic-sounding enough that any language is functional.

If I have a language that uses functions, is that functional too?
Jonathan Turner
@jonathandturner
Sep 21 2016 19:42
it's like saying everything is turing machine underneath
CodeTortoise
@CodeTortoise
Sep 21 2016 19:42
It helps to read up on the history of lisp, and what McCarthy created.
Turing-Machines don't literally exist, since can't store infinite memory.
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:43
The thing is though, Rust functions can still inherit variables from a higher scope, just like in C 'n' whatnot.
You don't have that nice enforcement of scoping
Jonathan Turner
@jonathandturner
Sep 21 2016 19:44
@CodeTortoise - yup, and similarly, you don't actually write in a lambda calculus because you don't have a means to decode
CodeTortoise
@CodeTortoise
Sep 21 2016 19:45
@jonathandturner Isn't decoding what the language does? Everything I am saying is just my mostly nascent understanding of how Rust, and off-topically Haskell works.
Jonathan Turner
@jonathandturner
Sep 21 2016 19:45
the lambda calculus is kind of a petri dish for programming language research. a way to see how features interact with each other in a fairly sterile environment
@CodeTortoise - hehe, the lambda calculus I'm talking about is the formal calculus
CodeTortoise
@CodeTortoise
Sep 21 2016 19:46
Ug. I am not mathy enough to further reply.
Jonathan Turner
@jonathandturner
Sep 21 2016 19:47
<-- spent too much time in grad school studying programming languages
CodeTortoise
@CodeTortoise
Sep 21 2016 19:47
@LeonineKing1199 Expressions vs Statements. But, I don't enough to really clarify.
I must more so that I can eventually enough.
@jonathandturner Then why do I argue with you? Hah!
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:48
Does that mean you can't just have a naked "if" in Rust?
Well, by "naked" I mean, without an else
Jonathan Turner
@jonathandturner
Sep 21 2016 19:48
you can have an if without an else
oooh, as an expression?
like: let x = if foo { 3 } else { 4 };
CodeTortoise
@CodeTortoise
Sep 21 2016 19:50
Better than ternary.
Jonas Platte
@jplatte
Sep 21 2016 19:50
Isn't if always an expression, and you can leave out the else when your if returns ()?
CodeTortoise
@CodeTortoise
Sep 21 2016 19:52
@jplatte If your if can return an (), don't you need to unwrap it as an Option?
Or Result, or whatever?
Jonas Platte
@jplatte
Sep 21 2016 19:52
What?
CodeTortoise
@CodeTortoise
Sep 21 2016 19:52
See. I am confused to.
too*
Jonas Platte
@jplatte
Sep 21 2016 19:52
Yeah but I don't understand your question
Jonathan Turner
@jonathandturner
Sep 21 2016 19:52
if you have an if at "statement-level" meaning as a statement by itself, you don't need an else
Jonas Platte
@jplatte
Sep 21 2016 19:53
() in rust is the equivalent to void in C / C++
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:53

you can have an if without an else

Ah see, that's a statement, isn't it?

Jonas Platte
@jplatte
Sep 21 2016 19:53
So you could say it's an if "statement", because it returns "nothing"
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:54
You can also have direct mutation as well.
CodeTortoise
@CodeTortoise
Sep 21 2016 19:54
Okay, I am really thinking about expressions that can either return Some T, or ()
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:54
It's nice that Rust const-qualifies everything by default.
But you can still mutate
Jonas Platte
@jplatte
Sep 21 2016 19:54
but really it is an expression that just always returns ().
Let me try...
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:54
Sure, if you want to win a gold medal in mental gymnastics
CodeTortoise
@CodeTortoise
Sep 21 2016 19:55
@LeonineKing1199 Man, I am just trying to get to bronze, or even an invitation to the games. @jplatte Blow up my mind!
Jonas Platte
@jplatte
Sep 21 2016 19:56
Compiles and works
So if-without-else is still an expression
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:57
Uh...
That might just be Rust doing some safety stuff for you
Jonathan Turner
@jonathandturner
Sep 21 2016 19:58
fun, learning something new today
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:58
Instead of C where printing void would give you UB
CodeTortoise
@CodeTortoise
Sep 21 2016 19:58
Okay.. so no type was given to unit, the expression evaluated to false, and the compiler inferred void?
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:58
Rust seems like it keeps things sane
Jonathan Turner
@jonathandturner
Sep 21 2016 19:58
CodeTortoise
@CodeTortoise
Sep 21 2016 19:58
Rust is the Rimmer of programming languages.
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:58
It's safe to say that Rust supports the functional paradigm for sure
Jonas Platte
@jplatte
Sep 21 2016 19:58
What's Rimmer? ^^
LeonineKing1199
@LeonineKing1199
Sep 21 2016 19:59
But calling it a functional language does seem false
CodeTortoise
@CodeTortoise
Sep 21 2016 19:59
One of the characters from Red Dwarf.
Jonathan Turner
@jonathandturner
Sep 21 2016 19:59
@CodeTortoise - the H?
CodeTortoise
@CodeTortoise
Sep 21 2016 19:59
British SciFi comedy
Jonathan Turner
@jonathandturner
Sep 21 2016 19:59
or whatever the hologram one was
CodeTortoise
@CodeTortoise
Sep 21 2016 19:59
Yes
Jonathan Turner
@jonathandturner
Sep 21 2016 19:59
+1 nerd score
CodeTortoise
@CodeTortoise
Sep 21 2016 20:00
That should be Gitter currency.
Wow, I got deja vu for all the times I suggested something should be currency.
Jonas Platte
@jplatte
Sep 21 2016 20:00
@LeonineKing1199 I guess the simplest explanation would be that if <cond> { <expr> } without an else afterwards is just syntactic sugar for if <cond> { <expr> } else { }
Jonathan Turner
@jonathandturner
Sep 21 2016 20:01
deju vu should be a currency!
Jonas Platte
@jplatte
Sep 21 2016 20:02
And if that doesn't explain it sufficiently, maybe it's good to know that similarily { [<expr>;]... } is basically syntactic sugar for { [<expr>;]... () }, so { } is the same as { () }.
CodeTortoise
@CodeTortoise
Sep 21 2016 20:03
So much sugar, I spend my mornings with a nice cup of black coffee with a little bit of Rust.
Jonas Platte
@jplatte
Sep 21 2016 20:03
so if { println!("..."); } is the same as if { println!("..."); () } else { () }, which should be relatively easy to parse as an expression that always returns ().
does that make sense? ^^
CodeTortoise
@CodeTortoise
Sep 21 2016 20:04
That makes sense @jplatte, I didn't even occur to me else statements would be necessary. And now I know what was meant by naked ifs
Jonas Platte
@jplatte
Sep 21 2016 20:05
awesome! :)
CodeTortoise
@CodeTortoise
Sep 21 2016 20:05
Like, if an if .... (expression!) was false, the program would move on.
But Rust expects a value.
mhsjlw
@mhsjlw
Sep 21 2016 21:01
still no tail call recursion therefore it is not in the functional paradigm...
:D
LeonineKing1199
@LeonineKing1199
Sep 21 2016 21:04
Lol true
You're not trully functional until all loops are recursions
Jonathan Turner
@jonathandturner
Sep 21 2016 21:05
ugh
CodeTortoise
@CodeTortoise
Sep 21 2016 21:05
@jonathandturner Rimmer is a hologram of a former crew member on the cargo ship Red Dwarf, brought back by the ships' computer to keep the main character Dave Lister sane. Rimmer has an H on his forehead to indicate he is a hologram.
Jonathan Turner
@jonathandturner
Sep 21 2016 21:06
@CodeTortoise - yup, I used to watch the show :)
CodeTortoise
@CodeTortoise
Sep 21 2016 21:06
.... Damn, I got belated gitter messages that confused me.
@mhsjlw Which obviously means erlang is the superior language.
mhsjlw
@mhsjlw
Sep 21 2016 21:52
Erlang <3
I'm more of an elixir guy though but I've got about 3 years of Erlang experience
although I wouldn't say it is superior, it's just aged a little more :D
elixir and rust together are unstoppable
I've used them both in production together, it's bliss. I love all the safety :P
CodeTortoise
@CodeTortoise
Sep 21 2016 22:03
Ooohh. I need to get better and faster at learning PLs so that I can be a proper polyglot, and actually be able to benefit from all the choice I have.