dneaves
@dneaves@lemmy.world
- Comment on Functional Programming vs. Object Oriented Programming 10 months ago:
Also, I take issue with the claim that OOP is all about “objects”. It’s also about classes.
Depending on the language, classes are just objects too. So its still just about objects.
- Comment on Unison | A friendly, statically-typed, functional programming language from the future · Unison programming language 11 months ago:
Hello world should look something like this:
print(“Hello, World”!)
You don’t need the annotation line in Haskell-esque languages, most of the time. Without the annotation, this is Hello World in Haskell:
main = print "Hello, World!"
And when you need more complexity, it can still be far simpler than Unison (or Haskell)
import qualified Data.List as List import Data.Function ((&)) processNumbers numbers = let isEven n = mod n 2 == 0 in numbers & List.filter isEven & List.map (^2) main = processNumbers [1, 2, 3, 4, 5, 6] & print
- Comment on Why does the for loop repeat in this recursion? 11 months ago:
i starts at 0, checks if i is less than n (the first time it will be, no matter what), prints a “#”, then increments i by 1 and loops
- Comment on Why does the for loop repeat in this recursion? 11 months ago:
Why does the for loop repeat after it exits to print a new line? If it exits the loop, shouldn’t it be done with it?
There’s the new line after the for loop to make sure that the next recursion starts on a fresh line. Otherwise the next recursion would print on the same line, right where it left off, and you’d just have a line of “#”'s. The for loop itself is just for printing “#”'s.
Why is n incremented and not i as stated with i++?
I think this is a confusion with the recursion. Look at the line with
draw(n - 1);
this happens before any printing of hashes happens, and only continues after its done. And it calls itself as long as it’s not less than or equal to 0. To psuedo-code the order of operations here:draw 3 { draw 2 { draw 1 { draw 0 {}; print "#" * 1; }; print "#" * 2; }; print "#" *3; };
so n is never incremented as you think, it just calls decremented versions of the draw function before the current one finishes. The i’s are purely involved in the for loop, which only prints hashes. Does that make sense?
- Comment on Unison | A friendly, statically-typed, functional programming language from the future · Unison programming language 11 months ago:
Although, i would agree with it not necessarily being “friendly”, since its a drastically different syntax than many beginners would be used to, the brackets and parenthesis here are not what you think they are.
Unison is a language in the style of Haskell, F#, Purescript, Elm, etc. So that first line is actually type annotations.
In Haskell, this would just be
main :: IO ()
, meaning a function named main with no arguments and produces what is essentally a potentially-unsafe IO action with a Void return (the empty parenthesis () ).Here in Unison they call the bracket part “abilities” or something. Its saying the same thing as Haskell, but being more explicit in saying it can raise an exception.
- Comment on [deleted] 1 year ago:
Agreed. Functional languages really raised my standard for what a language could be.
Stronger typing. More functional flow. Less dumb errors.
- Comment on Which programming language is hard to understand? 1 year ago:
Haskell for sure has a very sloped learning curve. The functional style, different syntax, a myriad of symbols and pragmas, as well as the tooling around it.
The only reason I was able to pick it up as quick as I did was because I was used to Elm due to my job. Then it was just learning about the IO type (and how to use it), cabal, stack, built-in symbols, and the most common pragmas.
But the symbols part is especially harsh, since symbols only hold meaning if they’re universally understood. Sure, the base- language ones are kinda adopted at this point, so they’ll stay, but the fact that external modules can also make symbols (sometimes without actually-named counterparts) adds some confusion. Like, would you just know what
.:
is supposed to mean off the top of your head? - Comment on need help with some fundamentals of for loops. it looks like im so close to fully grasping grabbing an item out of a list, but not quite. examples below 1 year ago:
Based on the first example:
If you want to help yourself a bit,
enumerate
your for loop. enumerate turns an iterable (like a list, or in this case a string) into an iterable of tuples, with contents being an int representing the index an item and the item itself:for (i, letter) in enumerate(chosen_word):
(Side note, the parenthesis surrounding
(i, letter)
are optional. I purposely included them to show that it’s a tuple.)i
will be the index of each character, andletter
will be the character itself. You can then do:if letter == guess:
And to wrap it up, do list assignment by index. Someone already mentioned why not to use insert in this scenario, so I won’t repeat them. The following will instead overwrite the item at
display
indexi
with the guessed character:display[i] = guess
- Comment on What's stopping WebAssembly from effectively replacing JavaScript? 1 year ago:
For transpiled-to-JS languages: Elm, Purescript, Typescript
I personally use Elm. Really helps remove all the JS funny business, without really having to type it (mostly)