Skip to content

Instantly share code, notes, and snippets.

@nicuveo
Last active August 1, 2023 09:59
Show Gist options
  • Save nicuveo/349732073e87f9c0a088d159c4499707 to your computer and use it in GitHub Desktop.
Save nicuveo/349732073e87f9c0a088d159c4499707 to your computer and use it in GitHub Desktop.
Cursed natural accessors in Haskell
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Lens.TH
--------------------------------------------------------------------------------
-- Characters
--
-- Some of the fields are only relevant to some characters, but are
-- here to allow for longer sentences.
data Character = Character
{ _name :: String
, _brother :: Character
, _antagonist :: Character
, _girlfriend :: Character
}
makeLenses ''Character
nobody = Character "nobody" nobody nobody nobody
mario = Character "Mario" luigi bowser peach
luigi = Character "Luigi" mario bowser daisy
peach = Character "Peach" nobody bowser nobody
daisy = Character "Daisy" nobody bowser nobody
bowser = Character "Bowser" nobody mario nobody
--------------------------------------------------------------------------------
-- English
s = id
(՚) = (^.) -- Armenian Apostrophe (U+055A)
--------------------------------------------------------------------------------
-- Japanese
の = (^.)
兄弟 = brother
名前 = name
彼女 = girlfriend
仇 = antagonist
--------------------------------------------------------------------------------
-- French
data L = L
l = L
L'x = x -- Fullwidth Apostrophe (U+FF07)
infixr 8 '
le = id
la = id
de = flip (^.)
du = flip (^.)
infixr 7 `de`
infixr 7 `du`
nom = name
frère = brother
copine = girlfriend
antagoniste = antagonist
--------------------------------------------------------------------------------
-- Usage
main = do
putStrLn $ luigi՚s brother՚s girlfriend՚s antagonist՚s name
putStrLn $ luigi `の` 兄弟 `の` 彼女 `の` 仇 `の` 名前
putStrLn $ le nom `de` l'antagoniste `de` la copine `du` frère `de` luigi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment