• CanadaPlus@lemmy.sdf.org
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    1 month 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
      1
      ·
      edit-2
      1 month 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 ()