Divyansh Prakash, September 2023
NOTE: Please read the previous post to understand the context of this post.
Divyansh Prakash, September 2023
NOTE: Please read the previous post to understand the context of this post.
In the Haskell world effect systems are currently a big thing and one of the most popular libraries on that front is effectful
.
When it comes to libries for creating webservices, the most popular one at the time of writing this is probably servant
.
The two libraries go very well together but it isn't exactly obvious how you can marry them up since there doesn't seem to exist any examples at the moment. That's why I decided to create one. I'll go through setting up a simple service line by line and at the end of post I'll post the whole example. So if you're just after some quick boilerplate you can scroll right to the end.
If you haven't already, create a new project using cabal init -i
.
Then let's add some dependencies to our cabal file. You can probably get away with loosening most of the constraints but with those the example is guaranteed to work on ghc-9.2.7
.
Every once in a while I investigate low-level backend options for PL-s, although so far I haven't actually written any such backend for my projects. Recently I've been looking at precise garbage collection in popular backends, and I've been (like on previous occasions) annoyed by limitations and compromises.
I was compelled to think about a system which accommodates precise relocating GC as much as possible. In one extreme configuration, described in this note, there
module Cube where | |
import Data.Functor.Const (Const(..)) | |
import Data.Functor.Product (Product(..)) | |
import Data.Functor.Sum (Sum(..)) | |
type (&&) = Product | |
type (||) = Sum |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE DerivingVia #-} |
{-# LANGUAGE GHCForeignImportPrim #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE UnboxedTuples #-} | |
{-# LANGUAGE UnliftedFFITypes #-} | |
module MutInt | |
( MutInt, | |
newMutInt, | |
getMutInt, | |
putMutInt, |
-- Defining a custom recursion scheme to manipulate two mutually-recursive | |
-- types, in the context of a toy bidirectional type checker. | |
{-# LANGUAGE DerivingStrategies, GeneralizedNewtypeDeriving, ScopedTypeVariables #-} | |
module Main where | |
import Test.DocTest | |
import Control.Monad (when) | |
import Data.Bifunctor (Bifunctor(bimap)) | |
import Data.Bifoldable (Bifoldable(bifoldMap), bitraverse_) |
import Data.List (unfoldr, partition) | |
import Data.Maybe (catMaybes) | |
import Criterion.Main (defaultMain, env, bgroup, bench, nf) | |
import System.Random (randomIO) | |
import Control.Monad (replicateM) | |
groupOn :: Eq k => (a -> k) -> [a] -> [(k, [a])] | |
groupOn k = unfoldr f . map (\x -> (k x, x)) | |
where | |
f [] = Nothing |
Check out the repo instead. The Wisdom of Quinn Now with 100% more archived PDFs.
Informative DevForum posts from everyone's favorite DTS member.
(Arranged newest to oldest)
:- use_module(library(pairs)). | |
:- use_module(library(reif)). | |
not_in_list(K, L) :- | |
if_((L = []), | |
true, | |
([X | More] = L, | |
dif(K, X), | |
not_in_list(K, More))). |