oleg at okmij.org oleg at okmij.org
Tue Dec 3 09:47:13 UTC 2013

```Andras Slemmer wrote:
> I stumbled upon something pretty neat, and although I'm 95% sure Oleg did

reification of constraint in December 2003, and almost in Haskell 98
(we needed Rank2 types though). It was described in the following
paper
We called this transformation reflection/reification.

I'm writing though to show a dual formulation to your development of
using singletons. It gets by without GADTs and uses very few extensions:

{-# LANGUAGE RankNTypes #-}

data Zero
data Succ a

class Class n
instance Class Zero
instance (Class m) => Class (Succ m)

-- Tagless final
class Sym repr where
z :: repr Zero
s :: repr n -> repr (Succ n)

newtype R x = R{unR:: x}                -- the identity interpreter

instance Sym R where
z = R undefined
s _ = R undefined

newtype S x = S Integer                 -- for show

instance Sym S where
z = S 0
s (S x) = S (x + 1)

newtype Reify n = Reify (forall a. (Class n => n -> a) -> a)

instance Sym Reify where
z = Reify (\f -> f (unR z))
s (Reify f) = Reify (\g -> f (g . unR . s . R))

genericClass :: (forall repr. Sym repr => repr n) -> (Class n => a) -> a
genericClass m f = case m of
Reify k -> k (const f)

```
{"ft_lang_label":"__label__en","ft_lang_prob":0.8184542,"math_prob":0.945595,"size":1460,"snap":"2020-45-2020-50","text_gpt3_token_len":437,"char_repetition_ratio":0.11332417,"word_repetition_ratio":0.0,"special_character_ratio":0.2979452,"punctuation_ratio":0.10175438,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9924459,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-01T18:23:02Z\",\"WARC-Record-ID\":\"<urn:uuid:ab56d7ab-2892-4796-960c-034ebca3a625>\",\"Content-Length\":\"4369\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:025c6cc4-b7c2-43f2-91bc-443026c206f2>\",\"WARC-Concurrent-To\":\"<urn:uuid:95fcd3d7-5fd3-4696-a905-2ce47c82a1bb>\",\"WARC-IP-Address\":\"23.253.242.70\",\"WARC-Target-URI\":\"https://mail.haskell.org/pipermail/haskell-cafe/2013-December/111625.html\",\"WARC-Payload-Digest\":\"sha1:NONA7TQX4JMMQZZK6OA5NSYNAITIYTXX\",\"WARC-Block-Digest\":\"sha1:HIIMOXQKWW2MGACD6EJTAACD22IBW37R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141681209.60_warc_CC-MAIN-20201201170219-20201201200219-00587.warc.gz\"}"}