Skip to content

Instantly share code, notes, and snippets.

View timjb's full-sized avatar

Tim Baumann timjb

View GitHub Profile
@timjb
timjb / archimedes.hs
Created November 1, 2016 13:53
Approximate pi using Archimedes' method
module Main (main) where
import Control.Monad (forM_)
-- | Given the length l of a cord from points A to B on the unit circle, compute
-- the length of the cords A-C and C-B, where C is the point on the unit circle
-- exactly in between A and B.
iterArchimedes :: Double -> Double
iterArchimedes l = l / sqrt (2 + sqrt (4 - l*l))
@timjb
timjb / LICENSE
Last active October 22, 2016 23:50
Trying to reproduce runtime error with persistent and runMigrationSilent
Copyright Tim Baumann (c) 2016
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@timjb
timjb / .gitignore
Last active August 9, 2016 23:26
Pijul Docker Container
pijul.org
sanakirja
@timjb
timjb / installing_pijul_on_macos.markdown
Last active July 6, 2021 14:03
Installing Pijul on macOS

Installing Pijul on macOS

Prerequisites

$ brew install openssl libssh
$ export LIBRARY_PATH=/usr/local/lib OPENSSL_LIB_DIR=/usr/local/opt/openssl/lib OPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include DEP_OPENSSL_INCLUDE=/usr/local/opt/openssl/include

Installing from crates.io

Nachtrag zum [FTypes-Vortrag beim Curry Club Augsburg][youtube]:

HasFType

Ich habe gezeigt, wie man mit FTypes einen bidirektionalen JSON-Parser für den Datentyp FGithubUser Identity schreiben kann. Nun ist das ja ein etwas unhandlicher Record-Datentyp, weil alle seine Feld-Werte noch mit dem Identity-Funktor gewrappt sind. Deshalb will man auch noch einen "ganz normalen" Datentyp

data GithubUser
  = GithubUser
  { userLogin :: T.Text

, userId :: GithubUserId

{-# LANGUAGE ExplicitForAll #-}
module WorksOnlyWithoutScopedTypeVariables where
myMap :: forall a b. (a -> b) -> [a] -> [b]
myMap = myMapWithSwappedVariables
where
myMapWithSwappedVariables :: (b -> a) -> [b] -> [a]
myMapWithSwappedVariables = fmap
@timjb
timjb / HashTable.hs
Created June 27, 2016 09:43
HashTable-Lückencode
#!/usr/bin/env stack
-- stack --resolver lts-6.4 --install-ghc runghc --package primitive --package hashable --package vector
module HashTable where
import Prelude hiding (lookup)
import Control.Monad.Primitive (PrimMonad (..))
import Data.Hashable (Hashable (..))
import qualified Data.List as L
import qualified Data.Vector.Mutable as VM
#!/usr/bin/env stack
-- stack --resolver lts-6.4 --install-ghc runghc --package unordered-containers --package QuickCheck --package hashable
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module DiffMonoid where
import Data.Hashable (Hashable)
import Data.Monoid ((<>))
import Test.QuickCheck
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
module PatternSynonymsImport where
-- one can use either an unqualified import
import PatternSynonymsTest
-- alternatively one can use explicit imports (this requires enabling the
-- PatternSynonyms language extension):
-- import PatternSynonymsTest (Option(..), pattern None)
maybeToOption :: Maybe a -> Option a
maybeToOption Nothing = None