News for hackers. Stuff that matters.
Re:Algebraic Data Types for C99 by bPspGiJT8Y on Friday May 10, 2024 @01:10AM (#40315671)
> And defining a function that will only accept particular variant is nice

This is possible to achieve (or hack your way through, if you will) by parameterizing the type and using a nullary type (a type which is impossible to have) to exclude specific cases of a sum type. In Haskell this would look like this:

    data Weather a b c = Sunny a | Rainy b | Snowy c

    -- can't snow in the summer!
    onlySummerWeather :: forall a b. Weather a b Void -> String
    onlySummerWeather weather = case weather of
      Sunny _ -> "Got sunny weather"
      Rainy _ -> "Got rainy weather"
      Snowy v -> absurd v
where `absurd :: forall a. Void -> a` "if you give me something you can't ever have, I will give you anything in return".
Re:Algebraic Data Types for C99 by mst on Friday May 10, 2024 @07:09AM (#40317534)
I would be so tempted to name the variable 'ity' instead of 'v'.
Re:Algebraic Data Types for C99 by Iceland_jack on Friday May 10, 2024 @08:31AM (#40318184)
By floating the forall., we get another representation type for Void (forall a. a) and `absurd' is one half of that isomorphism :)

    absurd :: Void -> (forall a. a)

    drusba :: (forall a. a) -> Void
    drusba void = void @Void