• 0 Posts
  • 14 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
    



  • 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).





  • Authoritarian state capitalism is different than liberal capitalism, I wasn’t trying to say they’re the same as the U.S, and you correctly outlined some differences that I agree with.

    As for beliefs, I also recognize many Chinese people believe they have socialism, just like many Americans believe that we live in a free democratic first world country. The similarity here is that both these takes are just state propaganda that have been successfully fed to the masses.

    China has successfully reverted anything remotely socialist about the country over the last 40 years. Like I’ve said previously, I recognize one day they might flip the switch, eliminate all the landlords & business owners, seize the means of production, and dissolve the State. I don’t believe this will happen though, and they’ve made no indication of even moving vaguely in this direction.

    If/when the day arrives that the workers own the means of production and are no longer wage slaves to a bourgeoise class, they will have successfully installed socialism. Before that day comes you can’t just execute a few billionaires and claim you have socialism, if you’re at all concerned with the true state of things.



  • 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.



  • I didn’t equate them all to Nazis, you have an incredibly simplistic black/white view of the world.

    The people who voted for Nazis weren’t a uniform mass of people. Some voted for them on promised economic reforms, some voted on the basis of making Germany great again, some voted for them because they disliked the Lügenpresse (lying press), which the Nazis talked about all the time. The thing all Nazi voters shared was that the anti-Jewish rhetoric didn’t turn them off to voting for the party.

    Similarly, there are a ton of Republicans who vote Republican for many reasons; promised economic reforms, making America great again, a dislike for “fake news”, etc. The thing all Republican voters share is that the anti-Mexican/anti-trans rhetoric doesn’t turn them off to voting for the party.

    They’re fine with the promise of building a wall to keep the Mexicans out. They’re fine with legislating against trans people. They’re fine with the rhetoric many southern Republicans are using about “solving the trans problem”, similar to the final solution rhetoric Nazis used.

    Republicans in 2023 are about as bad as Nazis were in 1930. That is to say, they’ve only done very lightweight rounding up of minorities and haven’t started killing them en masse. Whether or not the fascist wing of the Republican party wins out and successfully genocides minorities is anyone’s guess, but ignoring the similarities and history here is incredibly foolish.

    Not all people who voted Republican are horrible. Not all people who voted Nazi were horrible either. The platform can get better or worse, we’ve seen a history where it can get worse, but it’s also been shutdown before.

    Either way, having spaces online that disallow protofascist or fascist parties is fine and not “unhealthy”. Not every part of the internet has to allow for hateful rhetoric, it’s fine to have spaces geared towards gaming, community, or just people in agreement that people supporting a bigoted party shouldn’t be there.


  • There were people who voted for Nazis for “non-hateful” reasons, but it meant they didn’t care enough about the anti-jewish rhetoric to vote against it.

    It’s the same for Republicans and trans people/Mexicans/etc. The party is full of hateful bigots, yes there are some people who are indifferent to the hatred spewed and stand with Republicans on some other basis, but indifference towards bigotry is an issue in and of itself.

    Having a community explicitly ban people who support these bigoted groups (Republicans/Nazis/etc.) is not a problem. I prefer a space that allows people to share their views, I’ve debated self-identified fascists before, I’m fine in that environment, but I respect that some people aren’t.

    Just because someone doesn’t want to engage with hateful communities only makes them “too sensitive to go outside” if “outside” is sympathetic to these hateful groups.