Skip to content

Instantly share code, notes, and snippets.

View gdeest's full-sized avatar

Gaël Deest gdeest

  • Autogriff
  • Rennes, France
View GitHub Profile
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
@gdeest
gdeest / Main.hs
Created January 17, 2021 11:37
Example nested generic Servant API
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE RankNTypes #-}
#!/usr/bin/env stack
-- stack --resolver lts-16.0 --no-nix --system-ghc script
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecursiveDo #-}
import Data.Text.Lazy.IO as T
import LLVM.Pretty -- from the llvm-hs-pretty package
import LLVM.AST hiding (function)
import LLVM.AST.Type as AST
import qualified LLVM.AST.Float as F
import qualified LLVM.AST.Constant as C
(use-package flycheck)
(defvar-local flycheck-eglot-current-errors nil)
(defun flycheck-eglot-report-fn (diags &rest _)
(setq flycheck-eglot-current-errors
(mapcar (lambda (diag)
(save-excursion
(goto-char (flymake--diag-beg diag))
(flycheck-error-new-at (line-number-at-pos)
data Maybe a = Nothing | Just a
data Expr = SumExpr Expr Expr
| ProdExpr Expr Expr
| Power Expr Expr
| Val Float
String -> Maybe Expr
-- "1+2*3" → Just (SumExpr (Val 1.0) (ProdExpr (Val 2.0) (Val 3.0))
data Maybe a = Nothing | Just a
data Expr = SumExpr Expr Expr
| ProdExpr Expr Expr
| Power Expr Expr
| Val Float
String -> Maybe Expr
-- "1+2*3" → Just (SumExpr (Val 1.0) (ProdExpr (Val 2.0) (Val 3.0))
module Main where
import System.Environment
import System.Exit
type Filename = String
data Command = Foo Filename | Bar
parseCommand :: [String] -> Maybe Command
module Main where
import System.Environment
import System.Exit
type Filename = String
data Command = Foo Filename | Bar
parseCommand :: [String] -> Maybe Command