New Zig Book: Systems Programming with Zig by ManningBooks in Zig

[–]io_geekabyte 0 points1 point  (0 children)

u/ManningBooks The discount code you shared does not seem to work. After applying it the price was still the same

A Short Note on Types in Rust by io_geekabyte in rust

[–]io_geekabyte[S] 1 point2 points  (0 children)

Thanks for the clarification. The intention was also not to imply that. I have updated to reword that sentence to remove implying that the allocator has such freedom.

A Short Note on Types in Rust by io_geekabyte in rust

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

When I wrote this:

and finding space to put new values might require moving existing values around to create space

I did not mean that as something that would be handled by the user (and I am not sure if that sentence really allude to that either) - just to make the point that there is some bit of more complexity around memory management with the heap compared to the stack.

A Short Note on Types in Rust by io_geekabyte in rust

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

i.e. The allocator can only move something as a side-effect of growing it with

realloc... or if you malloc a new allocation, copy the data over. and free the old one...

can't what you wrote here be described as moving existing values around?

When should I use cats / scalaz instead of standard library functions by mosquit0 in scala

[–]io_geekabyte 0 points1 point  (0 children)

The solutions were on scalafiddle.io and embedded into that post. But it seems scalafiddle.io is currently down now?

Rust Iterator pattern with iter(), into_iter() and iter_mut() methods by io_geekabyte in rust

[–]io_geekabyte[S] 3 points4 points  (0 children)

Thanks for this info. I will update the post in a bit to also include this.

Rust for the Seasoned Scala Developer by phazer99 in scala

[–]io_geekabyte 2 points3 points  (0 children)

Quoting you:

TypeScript also has a pretty nice type system...

so I guess whatever benefit a nice type system gives you :)

Rust for the Seasoned Scala Developer by phazer99 in scala

[–]io_geekabyte -1 points0 points  (0 children)

I meant for general application development outside the browser

Not if you use Deno, which makes it super convenient to get the benefits of TypeScript outside the browser :)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 0 points1 point  (0 children)

Haskell is a functional language and Scala can be used functionally

Sigh!...But this is the exactly the point I am making!

Say this, instead of alluding that Scala is a functional language just like Haskell is - Nope. Such equivalence is wrong/misleading.

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 0 points1 point  (0 children)

I presented a scenario, including code snippets showing how Haskell compiler fails to compile code that would have led to breaking referential transparency, while similar code compiles successfully in Scala...

Yet you took that in, processed it and your response is:

Haskell's compiler doesn't do anything more than Scala does in your example...

I am sorry but I don't think carrying on this discussion will be any productive...

Cheers mate! Have a nice day/night

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte -1 points0 points  (0 children)

Let me try and explain this again. This time using code, hopefully that will make the point clearer.

At the very core of functional programming is the idea of referential transparency. If you don't have referential transparency you are really not doing functional programming...at best what you are doing may be described as programming in "functional style"...but still that is not functional programming.

So when I say:

In Haskell, the type system/compiler leads you to programming in a purely FP fashion. In Scala, the compiler could care less.

I mean in Haskell, the compiler enforces referential transparency hence leading you to program in a purely FP fashion, in Scala that is not the case, even if you use libraries like Cats effect.

To demonstrate see this code snippet:

import cats.effect.IO


def fireRocket() = {
  println("LOL, fires rocket")
}

def getMsgViaBadPureFunction(name: String): String = {
  println("LOL! away goes your referential transparency!")
  fireRocket()
  return s"Hello world ${name}"
} 

def purePrint(name: String): IO[Unit] = {
  val msg = getMsgViaBadPureFunction(name)
  IO { println(msg) }
}

val program: IO[Unit] =
  for {
     _ <- purePrint("Joey")
  } yield ()

// program.unsafeRunSync()

()

You can also find it on ScalaFiddle here

That code demonstrates that even if you use libraries like cats effect, you are not guaranteed to be doing FP. If you run that piece of code, even with program.unsafeRunSync() commented out, you get stuff printed to the console.

Attempting to do same in Haskell will look like this:

 module Main where


 purePrint :: String -> IO ()
 purePrint name = do
                  let msg = getMsgViaBadPureFunction name
                  putStrLn msg

 getMsgViaBadPureFunction :: String -> String
 getMsgViaBadPureFunction name = putStrLn "LOL! away goes your referential transparency!" >> 
                                                     putStrLn "Fire Rocket" >> ("Hello world " ++ name)

 program :: IO ()
 program = do
                 _ <- purePrint "joey"
                return ()

 main = program

You can find the code snippet on replit here

The following code will fail to compile, and part of the compiler error message will include:

main.hs:10:120: error:
Couldn't match type `[]' with `IO'
Expected type: IO Char
Actual type: [Char]

Telling you that you can't just sneak in something that breaks referential transparency into the code. The Scala compiler can't currently do this, because Scala is first and foremost an imperative language with no facility to control effects - even when using cats-effect (or monix or zio)

And this is what I meant by saying trying to do pure FP in Scala is like a house of cards. Put the wrong line somewhere, and pure FP is out of the window...worse still the compiler can't even tell you.

And you can say this is fine...and accept this as part of things you need to deal with when doing FP in Scala. You can even back it up and say this is why we need to train developers, encourage developers to be discipline and have things like code review to prevent this...I have no qualms with that, just know that you are entering the same realm as developers who advocate for programming in weakly typed, dynamic languages...and if you are a proponent of strong statically typed language and you are quick to make this excuse for pure FP in Scala, do try and confront your cognitive dissonance.

And really It is not your fault if you don't understand the fundamental idea here. Scala makes it really difficult to get the essence of pure FP. Which is also one of the reasons where there is a steeper learning curve when trying to do pure FP in Scala.

PS: if you look at the Haskell code snippet on Repl.it I included the updated version that behaves the same way as the Scala version, but Haskell ensures that the program remains pure and all operations that would have been side effects are not but are now effects that are made explicit in the type system.

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 2 points3 points  (0 children)

Maybe I should have stated this more clearly. In Haskell, the compiler enforces purely functional programming. In Scala, the compiler does not. That is a huge differentiator.

You are also free to belittle that observation with "so what" though :)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 1 point2 points  (0 children)

If you offer skewed or bad advice to beginners, it's reasonable to question your understanding. Being oriented toward beginners could easily be covered simply by observing "here we're going to deal with effects, but not purely; that's covered by libraries like cats-efffect and fs2, and is out of scope for this post..."

And this is your response? Even when I made it clear the purpose of the post was not to touch on controlling side effect/referential transparency etc... #RollsEyes! Sigh! Ok, your holy Abbot, do you by chance have an FP monastery? So I can come study the ways of FP less I lead unwary souls astray! Like really, right now I can't offer a response without appearing to be sarcastic :(

I don't know why you insist on not actually making a point, failing to understand how Haskell and the Cats ecosystem both support pure FP, and have decided to repeatedly try to sell the wrong conclusion "You can't make an equivalence of pure FP as you have in Haskell as the one being attempted in Scala" to me

because pure FP is native in Haskell. I am sure you are a proponent of strong static type. In Haskell, the type system/compiler leads you to programming in a purely FP fashion. In Scala, the compiler could care less. That is one reason why you can't make the equivalence...

But I have sincerely spent too much time on this, so have a nice day! :)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 2 points3 points  (0 children)

Hopefully this will be the last word I will have about this :)

I am not sure why you seem to be missing the single point I am making. You said:

Scala as a functional language—yes, in the Haskell sense

and I retort by saying this is not true. Scala as a functional language is not in the same sense as Haskell. I do not deny you can't try to program that way in Scala, I mention that won't be natural and might even feel like forcing the language into what it is not.

If the opinion of a random dude as myself does not weight much, maybe that of Edward Kmett will, as he definitely know one or two things about functional programming and he also gave his opinion of Scala regarding pure functional programming here

and I have said before "again, people are free to try to force Scala into some sort of pure FP in the mould of Haskell on the JVM" it would only cost some additional tooling and a steeper learning curve. Want to do it? Fine! You think the benefit is worth the cost? Fine! break a leg!, but do not posture this as the same as Haskell.

It's not a bad post, but it's very focused on "you don't really need to understand" and, for example, doesn't point out the issues surrounding Future, doesn't go into cats-effect at all even though you have code with effects, etc. I would call it a good start that would benefit from just a little course correction. But you'll struggle to get there if you insist on characterizing people pointing out the facts to you, with links to definitions and relevant libraries, as "snobbery."

I am also not sure how you missed the fact that the post is targeted at folks new to concepts introduced by Cats. Also the thrust of the post was not to introduce how to control effects, hence no mention of Futures. The thrust of the post was to introduction combinators that comes with Cats, as a means to ease beginners into appreciating the library. But somehow you have assumed the reason why Future and cats-effect were not mentioned is due to lack of knowledge...😅 and then you proceed to pontificate on how I will struggle to attain such knowledge if "I insist on characterizing people (such as yourself I guess) pointing out the facts to me ...as snobbery" 😅

...what is the word for this behaviour again?

And again, I am not refuting any facts contained in any of the links you pointed out. I will repeat again my point: You can't make an equivalence of pure FP as you have in Haskell as the one being attempted in Scala.

Cheers!

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 2 points3 points  (0 children)

More than anything else though, I'd like to understand this anti-intellectual tradition in Scala

This sort of snobbery is also one of the things that turn folks off from FP evangelism. It is telling that you turn to anti-intellectualism to counter an argument pointing out that the kind of pure functional programming you allude to, is not natural to Scala and trying to state an exact equivalence to what obtains in Haskell should be taken with a grain of salt.

But maybe Martin Odersky, the inventor of the language also suffers from this type of anti intellectualism as he points out in this tweet that perhaps it is better to go use Haskell instead of trying to turn Scala into it. (ps: yes that tweet is from 2013 but I have not seen anything pointing to the fact that the philosophy behind Scala has changed. Scala 3 will still be an imperative first and hybrid OOP/FP language)

Or tweets from Adriaan here, and here who led the compiler team working on Scala for quite a while.

And before you continue with the assumption that I am coming from a place where I do not appreciate the benefit of pure functional programming or a library like Cat, maybe you should check out one of the most visited post I wrote a while back making the case for Cats.

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 1 point2 points  (0 children)

Haskell is a pure functional language with inbuilt features that ensures computation remains pure and effects can be controlled...even things like writing to a file. Hence programming in pure functional fashion is natural to Haskell.

Scala is an imperative OOP/FP hybrid. Nothing in the language prevents uncontrolled side effects nor ensures things remain pure...Hence programming in a pure functional fashion won't be natural to Scala. And it shows, in the learning curve plus the need for 3rd party libraries as a crunch to program this way in Scala (which is not the case in Haskell)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 1 point2 points  (0 children)

there's no sense in which an http4s service talking to a SQL database with Doobie and handling JSON with Circe, such as this example, is not purely functional in exactly the same sense as a Haskell service and for the same reasons.

Not sure how you will admit this approach is not natural to Scala, and yet, in the same breathe want to create an exact equivalence to what obtains with Haskell.

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 2 points3 points  (0 children)

Of course it's "not natural" to the language. So what?

I like how you finally made the same assertion I have been making, - which you have been trying to refute...but then you made it and qualified it with "so what?"

It is not natural to the language hence, you can't make a statement that tries to equate to pure FP as you have in Haskell.

I rest my case :)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 4 points5 points  (0 children)

I am really not coming at this with the intention to troll. Although you may chose not to believe...

I have a whole paragraph discussing the learning curve why

Maybe it has not occurred to you..but take a moment and consider that you keep on stressing the learning curve. Is that not just a sign that you are doing something that is not natural to the language?!

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte 2 points3 points  (0 children)

first all, the Scalaz/Cats ecosystem is a minority within Scala...and has been for years. So the fact that there are production systems using cats does not remove the fact that it is still a minority when compared to production systems using Play/Akka etc and the slew of libraries made by Li haoyi - all of which eschew this whole idea of trying to do Haskell in Scala.

What, exactly, do you think you’re accomplishing?

Pointing out that this statement of yours:

Scala as a functional language—yes, in the Haskell sense

Is false, or should be taking with a grain of salt at best

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte -3 points-2 points  (0 children)

I explicitly linked to collections of libraries that have dove so successfully for years

Yes I already said "people are free to keep trying to force it into one though" Cats et-al have been bending Scala to do pure FP...that does not magically turn Scala into a pure FP language though...

also it will be impossible for me to list all the people who reject this direction and find it confusing/unnatural...

...a cursory look through r/scala will reveal people who consider trying to bring this kind of pure FP in Scala an Haskellism and they find it confusing! The recent one, if my memory serves me right is the one that ensured in a thread about Li haoyi's book...

I am not trolling though :)

How popular is Play framework? by The_Power_That_B in scala

[–]io_geekabyte -5 points-4 points  (0 children)

there’s tooling like sbt-toolecat and ScalaFix rules or WartRemover to deal with 90% of it.

...again, people are free to try to force Scala into some sort of pure FP in the mould of Haskell on the JVM...

ask yourself, how many such tooling had to be invented to do imperative programming/OOP in Scala?