• 0 Posts
  • 10 Comments
Joined 1 year ago
cake
Cake day: June 11th, 2023

help-circle
  • Nevoic@lemmy.worldtoProgrammer Humor@programming.devGolang be like
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    11 months ago

    Note: Lemmy code blocks don’t play nice with some symbols, specifically < and & in the following code examples

    This isn’t a language level issue really though, Haskell can be equally ergonomic.

    The weird thing about ?. is that it’s actually overloaded, it can mean:

    • call a function on A? that returns B?
    • call a function on A? that returns B

    you’d end up with B? in either case

    Say you have these functions

    toInt :: String -> Maybe Int
    
    double :: Int -> Int
    
    isValid :: Int -> Maybe Int
    

    and you want to construct the following using these 3 functions

    fn :: Maybe String -> Maybe Int
    

    in a Rust-type syntax, you’d call

    str?.toInt()?.double()?.isValid()
    

    in Haskell you’d have two different operators here

    str >>= toInt &lt;&amp;> double >>= isValid
    

    however you can define this type class

    class Chainable f a b fb where
        (?.) :: f a -> (a -> fb) -> f b
    
    instance Functor f => Chainable f a b b where
        (?.) = (&lt;&amp;>)
    
    instance Monad m => Chainable m a b (m b) where
        (?.) = (>>=)
    

    and then get roughly the same syntax as rust without introducing a new language feature

    str ?. toInt ?. double ?. isValid
    

    though this is more general than just Maybes (it works with any functor/monad), and maybe you wouldn’t want it to be. In that case you’d do this

    class Chainable a b fb where
        (?.) :: Maybe a -> (a -> fb) -> Maybe b
    
    instance Chainable a b b where
        (?.) = (&lt;&amp;>)
    
    instance Chainable a b (Maybe b) where
        (?.) = (>>=)
    

    restricting it to only maybes could also theoretically help type inference.


  • Nevoic@lemmy.worldtoProgrammer Humor@programming.devGolang be like
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    11 months ago

    Here’s an example (first in Haskell then in Go), lets say you have some types/functions:

    • type Possible a = Either String a
    • data User = User { name :: String, age :: Int }
    • validateName :: String -> Possible String
    • validateAge :: Int -> Possible Int

    then you can make

    mkValidUser :: String -> Int -> Possible User
    mkValidUser name age = do
      validatedName ← validateName name
      validatedAge  ← validateAge age
      pure $ User validatedName validatedAge
    

    for some reason <- in lemmy shows up as &lt;- inside code blocks, so I used the left arrow unicode in the above instead

    in Go you’d have these

    • (no Possible type alias, Go can’t do generic type aliases yet, there’s an open issue for it)
    • type User struct { Name string; Age int }
    • func validateName(name string) (string, error)
    • func validateAge(age int) (int, error)

    and with them you’d make:

    func mkValidUser(name string, age int) (*User, error) {
      validatedName, err = validateName(name)
      if err != nil {
        return nil, err
      }
    
      validatedAge, err = validateAge(age)
      if err != nil {
        return nil, err
      }
    
      return User(Name: validatedName, Age: validatedAge), nil
    }
    

    In the Haskell, the fact that Either is a monad is saving you from a lot of boilerplate. You don’t have to explicitly handle the Left/error case, if any of the Eithers end up being a Left value then it’ll correctly “short-circuit” and the function will evaluate to that Left value.

    Without using the fact that it’s a functor/monad (e.g you have no access to fmap/>>=/do syntax), you’d end up with code that has a similar amount of boilerplate to the Go code (notice we have to handle each Left case now):

    mkValidUser :: String -> Int -> Possible User
    mkValidUser name age =
      case (validatedName name, validateAge age) of
        (Left nameErr, _) => Left nameErr
        (_, Left ageErr)  => Left ageErr
        (Right validatedName, Right validatedAge) => 
          Right $ User validatedName validatedAge
    


  • I’m on Linux full time for programming and gaming. I play battle.net games (WoW, hearthstone, overwatch, HoTS, WoW classic), League of Legends, and a lot of steam games. I have virtually no issues. I have a ryzen 5900x and a RTX 3080.

    The key to Linux gaming (outside of steam) is Lutris. You just search the game you want to install, and it installs all the dependencies needed automatically and you can launch the game from one place. They even have a simple 1 click button for adding steam games too if you want a single launcher for every game you have (this is what I do).

    The only issues I really have are with EAC, like DKO didn’t work for a bit after it came out (but does now), and Valorant/Fortnite don’t work (they can easily enable Linux EAC but choose not to). I happen to not play these games so it’s a non-issue for me, but worth mentioning.

    League of Legends is also worth mentioning as having more issues than the rest. Usually I can run the game for months or even a year+ with no issues, but earlier this year the game was virtually unplayable on Linux for about 6 days due to a bug Riot Games added. This bug also effected Windows users, but to a much less extent. They would get disconnected once every couple games, while Linux users would get disconnected once every couple minutes. The League of Linux community is amazing though, and people were troubleshooting it constantly and making it more and more playable (getting to Windows parity on the bug), until Riot Games fixed it on their end.

    I even helped my brother swap from Windows to Linux recently. He isn’t super into Linux or anything, but he was having consistent issues on Windows with his monitor turning off in games, specifically League. We tried reinstalling drivers, watching temps, reinstalling League (since it didn’t happen in other games), and uninstalling certain apps that can add overlays (though they were disabled). Some of these issues seemed to fix it until it returned usually hours or days later. Eventually we gave Linux a try and the issue is entirely gone. It’s likely that resetting windows would work too, but he dual boots and it’s easier to not have to reinstall everything.


  • “from a private third party” where? A (non-foolish) socialist would advocate for rules against renting people, just like we’re not allowed to buy people right now.

    That would mean there would be no private third parties that are renting out factories of rented workers.

    If what you’re saying is “from a private third party outside the socialist space”, then that’s a problem for all kinds of socialist spaces. We can’t control productive forces outside of the space we have domain over.


  • It sounds like the market socialists you’ve been talking to haven’t been socialists if they’re in favor of private property, that’s strictly a capitalist position. They’re probably just welfare capitalists.

    An actual market socialist is against private entities owning the means of production, they’re owned communally by some mechanism (be it some democratically run cooperative, the state, etc .) It wouldn’t be a group of stakeholders that are a separate, private entity disconnected from the workers (though the state arguably is an entity like that, and that’s where the line between state socialism and state capitalism gets blurry).


  • I’m a huge anti-capitalist/socialist, and often times I find it useful to use this mix-up of markets and capitalism in my favor.

    When people say “but we need capitalism because the alternative to markets is so bad” I say plainly that I’m not advocating against markets, I’m advocating against classes. The vast majority of self-described capitalists aren’t trying to defend massive corporations or employer exploitation, they’re defending markets.

    If all those pro market capitalists became market socialists, dismantling capitalism would be far easier, then we could have much more interesting discussions about the merits of markets and when to use them versus centralized planning, without a leech class exploiting wage slaves or scalping houses.


  • On this note it’s crazy there are people who will spend over $100 on a Windows license, when all they do is use a web browser or simple productivity apps like spreadsheets or word.

    I can get if you’re using some adobe products, or some game that hasn’t been updated to the Linux compatible EAC, but for the vast majority of people paying over $100 (or having that cost passed onto you from the manufacturer if Windows is preinstalled) is crazy.


  • People should separate the quality of the products, produced by the workers, from the batshit insane politics and mindset of the owners. I have a Tesla, and I recognize Elon is a protofascist dick, but the CEOs of other companies are just better at maintaining their image, they’re part of the same parasitic class that Elon is a part of.

    I bought a Tesla for the power, infrastructure, etc. but I don’t generally recommend Teslas. If you don’t care about 0-60 time, and you can hold out until 2024/2025, lots of EVs will adopt the NACS standard and be able to use almost the entire supercharging network. Other vehicles will likely be better and/or cheaper.


  • Mostly agree, but the “incentive” focus is a misnomer. Humans don’t just sit around and stare at walls when they’re not “incentivized”. Incentives in sociopolitics is just a rebranding of coercion, getting people to do things they don’t want to do. People are incentivized/coerced to work at McDonald’s because otherwise they’ll live on the streets, the housing scalpers will make sure of it.

    FOSS exists and isn’t at risk of dying. Yeah, it’s ideal if the people working on FOSS things don’t have to also work a soul crushing day job, and yeah maybe when their soul is crushed they’ll lose interest in the things they enjoy doing, but we shouldn’t frame that as them getting jaded towards FOSS projects. It’s actually just depression, and it impacts other hobbies too.

    All that being said, I’m all for donations to people who do FOSS work so they can escape and do the things they love, it means better FOSS products and happier developers.