Skip to content

Instantly share code, notes, and snippets.

@friedbrice
friedbrice / MOVED.md
Last active July 27, 2020 06:02
Stack wrapper for single-file haskell programs.
@friedbrice
friedbrice / haskell-time.hs
Last active April 4, 2024 16:09
Haskell Time Crib Sheet
-- ghcid -c'stack repl --resolver nightly --package time' haskell-time.hs --allow-eval
----
-- # Haskell Time Crib Sheet
----
-- Excellent sources for this small guide include:
--
-- * https://two-wrongs.com/haskell-time-library-tutorial.html
-- * https://williamyaoh.com/posts/2019-09-16-time-cheatsheet.html
@domenkozar
domenkozar / README.md
Created June 23, 2020 08:18
Haskell + GitHub Actions + Cachix
@OliverJAsh
OliverJAsh / foo.md
Last active September 4, 2023 15:31
`Option` vs non-`Option`

Option vs non-Option

Option<T> non-Option (T | undefined)
accessing property userOption.map(user => user.age) userNullish?.age
calling a method userOption.map(user => user.fn()) userNullish?.fn()
providing fallback ageOption.getOrElse(0) ageNullish ?? 0
filter ageOption.filter(checkIsOddNumber) `ageNull
@chrisdone
chrisdone / Intro.md
Last active May 20, 2024 12:44
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

@edmundsmith
edmundsmith / writeup.md
Created July 7, 2019 20:47
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

@ChrisPenner
ChrisPenner / GenericMonoid.hs
Last active February 22, 2019 19:51
Derive Monoid for using Generics
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module GenericMonoid where
import Data.Monoid
import Data.Maybe
@jkachmar
jkachmar / Main.hs
Last active May 19, 2022 13:20
"Simple" example for how to set up Servant to automatically retry its client requests
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
@dcastro
dcastro / usage.scala
Last active December 6, 2018 12:39
"Newtype" deriving for scala
import org.scalacheck.cats.implicits._
import org.scalacheck.Gen
import io.circe.{Decoder, Encoder}
object Test extends App {
case class X(i: Int)
implicit val x: Encoder[X] = Wrapper[X].deriveInstance[Encoder]
implicit val y: Decoder[X] = Wrapper[X].deriveInstance[Decoder].withErrorMessage("some custom error msg")
val z: Gen[X] = Wrapper[X].lift(Gen.choose(0, 10))
@carymrobbins
carymrobbins / NumericLits.hs
Last active November 16, 2018 23:42
Huge hack to support explicit numeric literals in Haskell
{- TODO: The Num and Fractional instances don't implement all methods.
- In practice this is fine but for completeness they should be done.
-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module NumericLits where
data I = I
i :: I