ghc-9.6.1です。 GHCはChar kindが9.2で入ったので型レベルパーサーが書ける様になってるんですよね。ということで書いてみました。 BNFは以下です: expr ::= term *('+' term) term ::= factor *('*' factor) factor ::= '(' expr ')' | nat nat ::= 0 | 1 | 2 | ... | 9 {-# Language TypeData #-} {-# Language DataKinds #-} {-# Language TypeFamilies #-} {-# Language UndecidableInstances #-} {-# Language TypeApplications #-} {-# Language MagicHash #-} {-# LANGUAGE NoStar
![Haskellで型レベルパーサー](https://cdn-ak-scissors.b.st-hatena.com/image/square/f9ccbbf91251d47051e675e728b3c6757e7c5303/height=288;version=1;width=512/https%3A%2F%2Fres.cloudinary.com%2Fzenn%2Fimage%2Fupload%2Fs--MW1sKW6I--%2Fc_fit%252Cg_north_west%252Cl_text%3Anotosansjp-medium.otf_55%3AHaskell%2525E3%252581%2525A7%2525E5%25259E%25258B%2525E3%252583%2525AC%2525E3%252583%252599%2525E3%252583%2525AB%2525E3%252583%252591%2525E3%252583%2525BC%2525E3%252582%2525B5%2525E3%252583%2525BC%252Cw_1010%252Cx_90%252Cy_100%2Fg_south_west%252Cl_text%3Anotosansjp-medium.otf_37%3Aruicc%252Cx_203%252Cy_121%2Fg_south_west%252Ch_90%252Cl_fetch%3AaHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EtL0FPaDE0R2k3Y3RSeUZPT3dOd1k2eTlobG1Hc2Q1NXB4SXVxZlFNZU5idThHcVE9czI1MC1j%252Cr_max%252Cw_90%252Cx_87%252Cy_95%2Fv1627283836%2Fdefault%2Fog-base-w1200-v2.png)