• Aurenkin@sh.itjust.works
    link
    fedilink
    arrow-up
    48
    ·
    17 days ago

    Priest: If you are not yet baptised, I baptise you in the name of the father, the son and the holy spirit. Else break.

    Parents: *sweating nervously*…else what

  • CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    13
    ·
    edit-2
    17 days ago

    That honestly seems like the best way to write conditionalBaptize but I still hate it. Probably because IRL you’d just rewrite baptism instead of retrofitting the function with a clever use of id.

    • solrize@lemmy.ml
      link
      fedilink
      arrow-up
      10
      ·
      edit-2
      17 days ago

      This is probably an ok use for a GADT. Something like:

      {-# LANGUAGE DataKinds      #-}
      {-# LANGUAGE GADTs          #-}
      {-# LANGUAGE KindSignatures #-}
      
      data Bap = Baptized | Unbaptized
      
      data Person :: Bap -> * where
         Baptize :: Person Unbaptized -> Person Baptized
         NewPerson :: Person Unbaptized
      
      conditionalBaptize :: Person a -> Person Baptized
      conditionalBaptize p =
          case p of NewPerson -> Baptize p
                    Baptize _ -> p
      
      main = return ()
      
    • expr@programming.dev
      link
      fedilink
      arrow-up
      5
      ·
      edit-2
      17 days ago

      It looks pretty normal to me as a professional Haskeller, though I suppose it’s perhaps slightly cleaner to write it as conditionalBaptize p = fromMaybe p $ baptize p. It’s largely just a matter of taste and I’d accept either version when reviewing an MR.

      Edit: I just thought of another version that actually is far too clever and shouldn’t be used:

      conditionalBaptize = ap fromMaybe baptize, making use of the monad instance for ->. But yeah, don’t do this.

  • Alph4d0g@discuss.tchncs.de
    link
    fedilink
    arrow-up
    4
    ·
    16 days ago

    I’m not religious but I thought baptism was always conditional on confirmation - not in writing or scripture but via a handshake agreement with the parents or some shit.

    • solrize@lemmy.ml
      link
      fedilink
      arrow-up
      8
      ·
      17 days ago

      There’s an old joke about functional programming separating Church from state.