Example of prometheus-haskell
docker-compose.yaml:
version: '3'
services:
prometheus:
image: prom/prometheus:v2.30.3| -- | >>> measure (return $ sum [1..100000000]) | |
| -- (5000000050000000,1.892e-6) | |
| measure :: IO a -> IO (a, Double) | |
| measure io = do | |
| start <- getMonotonicTimeNSec | |
| a <- io | |
| end <- getMonotonicTimeNSec | |
| return (a, fromIntegral (end - start) / 1_000_000_000) | |
| -- | >>> measure (return $ sum [1..100000000]) |
Example of prometheus-haskell
docker-compose.yaml:version: '3'
services:
prometheus:
image: prom/prometheus:v2.30.3ghc -O2 -ddump-simpl -ddump-to-file Main.hs:
==================== Tidy Core ====================
2022-08-01 14:09:19.73363688 UTC
Result size of Tidy Core
= {terms: 178, types: 217, coercions: 9, joins: 0/0}
Suppose we have:
data MyType = MyType
{ myTypeA :: Maybe A
, myTypeB :: Maybe B
}How do we guarantee that at least one field is non empty?
| {- Point-Free or Die: Tacit Programming in Haskell and Beyond | |
| https://www.youtube.com/watch?v=seVSlKazsNk | |
| g . f = (.) g f x | |
| = \x -> g (f x) | |
| = \x -> g $ f x | |
| = \x -> g . f $ x | |
| = g . f |
Will they produce the same CORE? With -O2 they do.
newtype A a = MkA { unA :: a }
deriving newtype Show
data B = B [A String]
deriving stock Show
foo :: [String] -> BGiven the following type families:
type family Elem a as where
...
type family NotElem a as where
...| -- Source: Fun with Type Functions | |
| data L | |
| data V a | |
| data f1 :<>: f2 | |
| type Parser a = String -> [(a, String)] | |
| type Printer a = a -> String | |
| data F f where |
| {-# LANGUAGE AllowAmbiguousTypes #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE DefaultSignatures #-} | |
| {-# LANGUAGE DeriveAnyClass #-} | |
| {-# LANGUAGE DeriveGeneric #-} | |
| {-# LANGUAGE DerivingStrategies #-} | |
| {-# LANGUAGE DerivingVia #-} | |
| {-# LANGUAGE FunctionalDependencies #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} |
| -- | Type constructor name | |
| type TyConsName :: (Type -> Type) -> Symbol | |
| type family TyConsName rep where | |
| TyConsName (D1 (MetaData tyConName _ _ _) _) = tyConName | |
| -- | 'KnownSymbol s' for the 'TyConsName' of 'a' | |
| type Render :: Type -> Constraint | |
| type Render a = KnownSymbol (TyConsName (Rep a)) | |
| -- | Given a 'Generic a', returns the name of its type constructor. |