This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Language.C.DSL | |
import Language.Format | |
main = prettyPrint $ do | |
include "stdio.h" | |
includeLocal "foo.h" | |
intptr_t <- typedef (ptr int) "intptr_t" | |
x <- int "x" | |
y <- double "y" | |
z <- ptr intptr_t "z" | |
w <- carray int "w" 21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nan = 0/0 | |
silenceNaN d = if isNaN d then 0 else d | |
cumSumWithMissing :: [Double] -> [Double] | |
cumSumWithMissing ds = let | |
ret = scanl1 (+) $ silenceNaN <$> ds | |
go x y = if isNaN x then x else y | |
in zipWith go ds ret | |
foo :: [Double] -> [Double] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- see https://docs.google.com/presentation/d/1f-avqUksUCO8vvwn1KQNu-LIVwqNc1EbQz1l_stTD8o/edit#slide=id.gf6104008a_0_810 | |
{-# LANGUAGE RankNTypes #-} | |
type PersonLambdas = forall a. (String -> Int -> a) -> (String -> Int -> Double -> a) -> a | |
child :: String -> Int -> PersonLambdas | |
child s i = \childL adultL -> childL s i | |
adult :: String -> Int -> Double -> PersonLambdas | |
adult s i d = \_ adultL -> adultL s i d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, fetchurl, gettext, attr }: | |
stdenv.mkDerivation rec { | |
version = "0.4.0"; | |
name = "ta-lib-${version}"; | |
src = fetchurl { | |
url = "http://prdownloads.sourceforge.net/ta-lib/${name}-src.tar.gz"; | |
sha256 = "0lf69nna0aahwpgd9m9yjzbv2fbfn081djfznssa84f0n7y1xx4z"; | |
}; | |
nativeBuildInputs = [ gettext ]; | |
buildInputs = [ attr ]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- Fun with phantom types. Type safe doubles. #-} | |
-- this lets us derive the Num implementation | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
-- P stands for Phantom, or Parametrized type | |
newtype P a b = Wrap { unwrap :: b } deriving Num | |
deriving instance Floating b => Floating (P a b) | |
deriving instance Fractional b => Fractional (P a b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat turing.hs | |
-- this is a finite memory tape with dereference and assign | |
import Control.Monad.State | |
import qualified Data.Map as Map | |
import Data.Word | |
type Ptr = Word64 | |
-- a C-like array (char *) which maps int64 to int8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Val a = Val Int deriving Show | |
instance Functor Val where | |
fmap _ (Val x) = Val x | |
coerce :: Val a -> Val b | |
coerce = fmap undefined | |
data Void | |
x :: Val Int | |
x = Val 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- These are straightforward. Just map or zipWith all operations. | |
-- The only interesting one is fromInteger, typically when people | |
-- do an operation on a vector and a scalar, they mean to run it | |
-- over the vector. E.g. [1,2,3] * 1. | |
instance Num a => Num [a] where | |
(+) = zipWith (+) | |
(*) = zipWith (*) | |
abs = map abs | |
signum = map signum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies, DataKinds, PolyKinds, TypeOperators #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# OPTIONS_GHC -fwarn-unticked-promoted-constructors #-} | |
import Prelude hiding (lookup) | |
import qualified Data.Map as Map | |
type family Equal a b :: Bool where | |
Equal a a = 'True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
module Main where | |
import Data.Monoid | |
import Control.Comonad | |
import Data.Fix | |
import Data.Foldable as Foldable | |
newtype Cell a b = Cell { runCell :: Either () ((,) a b) } deriving (Functor) |
OlderNewer