Use the template haskell (abbreviated to "TH") extension in a module with:
{-# LANGUAGE TemplateHaskell #-}
There are a few key pieces of syntax:
{-# LANGUAGE TypeOperators, LambdaCase, StandaloneDeriving, GADTs #-} | |
data Type env t where | |
-- A constant type. Add kinds? | |
-- Maybe, (), Int, Either, (->), etc. | |
Constructor :: kind -> Type env kind | |
-- A free variable. | |
-- a | |
FreeVariable :: kind -> Type env kind | |
-- Type application. |
-- | Load a renamed cell. | |
resolveRenamedCell :: | |
Map Hash (Either LoadError LoadedExpression) | |
-> FillerEnv LoadError | |
-> IsRenamed (Expression Renamed) | |
-> RIO DocumentReader (Either LoadError (IsResolved (Expression Resolved))) | |
resolveRenamedCell globalTypes globalHashes isRenamed = do | |
hasConstraints <- | |
pure $ | |
first LoadGenerateError $ |
fineGrained :: Spec | |
fineGrained = do | |
describe | |
"Successful" | |
(do it "a ~ a" (shouldReturn (unifyConstraints' [a .~ a]) (pure [])) | |
it | |
"Integer ~ Integer" | |
(shouldReturn (unifyConstraints' [_Integer .~ _Integer]) (pure [])) | |
it | |
"a ~ b" |
{-# LANGUAGE DataKinds #-} | |
-- | My database API. | |
module DBAPI where | |
import Data.Defaults | |
data ConnSpec p = ConnSpec | |
{ username :: !(Required p String) |
22-03-21 13:32:52.939 $ cat /opt/hindent-ormolu | |
#!/bin/bash | |
/opt/ormolu-0.1.4.1 \ | |
"--ghc-opt" "-XBangPatterns" \ | |
"--ghc-opt" "-XNumericUnderscores" \ | |
"--ghc-opt" "-XOverloadedLabels" \ | |
"--ghc-opt" "-XPatternSynonyms" \ | |
"--ghc-opt" "-XTypeApplications" \ | |
"--mode" "stdout" |
I've been working on a parser for a Haskell-like syntax called Duet. In the implementation I've taken particular care to make an awesome tokenizer and parser that is super helpful to learners.
Jasper Van der Jeugt made a talk about producing good error messages recently, which coincides nicely with my parallel work on this. So I thought I'd also share my
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
-- | Print STG in GHC 8.4.3. | |
module Main where | |
import Control.Monad.IO.Class (liftIO) | |
import qualified CorePrep |
Total (non-error-throwing) lambda-calculus evaluators.
Appendix 2 | |
Continued Fraction Arithmetic | |
by |