• 0 Posts
  • 11 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
    1 year 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
    1 year 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
    


  • That’s the idea, but in practice since the data exists independently on each server, it takes network time and computational time for them to align. In practice I expect comments to function as you expect, and upvotes to be slightly off depending on which instance you’re viewing from.

    Things get a bit more weird when an instance gets defederated from another instance. My understanding here is that if you have instance A defederate from instance B, but instance B was listening to some of instance A’s communities, that instance B will have an independent replica of that community that doesn’t sync (this happened when beehaw defederated from open registration instances like lemmy.world).



  • If you’re not going to spend the 60 seconds it takes to read my comment, don’t bother responding. Nobody mentioned a conspiracy to cull the population, the millions of people who are dying a year from hunger or entirely curable diseases like TB aren’t dying because of some deep state conspiracy, they’re dying because it’s what’s logical in a capitalist economy. These people have no economic power, so they get no resources.

    Similarly, as the economy gets further automated, workers lose economic power, and we’ll be treated with the same capitalist logic that anyone else in the world is treated with, once we have no economic power we are better off dead, and so that’s what will happen.

    The position that “alternative industries will always exist” is pretty foolish, humans aren’t some exceptional supreme beings that can do something special artificial beings cannot. Maybe you’re religious and believe in a soul, and you think that soul gives you some special powers that robots will never have, but you’d be simply mistaken.

    Once the entire economy is automated, there will still be two classes, owners and non-owners, instead of owners and workers. Non-owners will either seize the means of production or die per the logic of capitalism (not some conspiracy).


  • Suggesting an alternative industry as an escape from AI doesn’t work. The media tried this with the millions of truck drivers, pushing them to go into software development 5-10 years ago, as we started conversations around the impending automation of their careers.

    The thought at the time, and this seemed like an accurate forecast to me, was that the tech industry would continue to grow and software engineers would be extraordinarily safe for decades to come. I was already in this profession, so I figured my career was safe for a long while.

    Then a massive AI boom happened this year that I hadn’t anticipated would come for 15ish more years, and similarly AI experts are now pushing up predictions of AGI by literally decades, average estimates being under 10 years now instead of 30 years.

    At the same time, the tech industry went through massive layoffs. Outsourcing, massive increases in output with generative AI automating away repetitive copy/paste programming or even slightly more complicated boilerplate that isn’t strictly copy/paste, amongst natural capitalist tendencies to want to restrict high value labor to keep it cheap.

    Those people who shifted away from truck driving and towards software engineer 4+ years ago, thinking it was a “safe path” and now being told that it’s impossible to find a junior dev position might become desperate enough to change paths again. Maybe they’ll take your advice and join a trade school, only to find in 4 years we’ll hit massive advancements in robotics and AGI that allows general problem solving skills from robots in the real world.

    We already have the tech for it. Boston dynamics has showcased robots that can move more than fluently enough to be a plumber, electrician, etc. Now we just need to combine generative AI with senses and the ability to process information from those senses and react (this already works with images, moving to a video feed and eventually touch/sound/etc is a next step).

    While everyone constantly plays a game of chicken, trying to move around this massive reserve army of labor, we’ll see housing scalpers continue to raise rents, and cost of living becoming prohibitive for this growing class of underemployed or unemployed people. The reserve army of labor, when kept around 5-10% of the population, serves as an incentive for people to be obedient workers and not to rock the bed too much. That number growing to 20-50% is enough to rock the bed, and capitalists will advocate for what they’ve already advocated in the third world, a massive reduction or total annihilation of welfare, so millions more can starve to death.

    We already have millions of people dying a year due to starvation, and nearly a billion people are malnourished due to lack of food access. Raising this number is a logical next step for capitalists as workers try to fight for a share of the automated economy.


  • We have 3 paths forward:

    • liberal capitalist solution (à la Tucker Carlson): ban AI and allow workers to do bullshit jobs
    • alternative liberal capitalist solution: let excess workers die in the streets because they’re no longer needed for production
    • socialist solution: distribute the means of production (AI in this case) so we can share equitably in its output

    I’d advocate for the socialist one, it sounds like you might be more in line with Tucker Carlson’s thinking here?


  • I didn’t tell anyone how to run anything, I pointed out how they’re an entirely capitalist nation that pretends to be socialist. Maybe the current authoritarian regime will suddenly revert all the market reforms they’ve implemented over the last 3-4 decades, seize the means of production, and then dissolve the state when it’s no longer needed.

    I don’t believe this will happen, and I don’t think many people do. Most of the “socialists” that support China are more than happy with the bourgeoise class existing and exploiting working class people “for the betterment of the State”. This kind of thinking falls much more in line with Mussolini than Marx.