this post was submitted on 17 Aug 2025
535 points (99.3% liked)

Programmer Humor

25776 readers
1432 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] CanadaPlus@lemmy.sdf.org 13 points 23 hours ago* (last edited 23 hours ago) (4 children)

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 10 points 23 hours ago* (last edited 23 hours ago) (2 children)

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 ()
[–] KazuchijouNo@lemy.lol 13 points 22 hours ago (1 children)

Thank you for refactoring baptism. How do we push this to production now?

[–] Stizzah@lemmygrad.ml 4 points 22 hours ago

Hey hey hey, let's start with a PR, we are not savages here aren't we?

load more comments (1 replies)