Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env stack
{- stack --resolver lts-9.21 script
--package shelly --package text
-}
{-# OPTIONS_GHC -Wall -Werror #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
#!/usr/bin/env stack
-- stack --resolver lts-9.21 script --package loch-th
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -Wall -Werror #-}
import Debug.Trace.LocationTH (check)
import System.Environment (getArgs)
main :: IO ()
main = do
@vvv
vvv / applicative-something.hs
Created March 28, 2018 18:37
Looking for idiomatic way to write expression with `Applicative`
#!/usr/bin/env stack
-- stack --resolver lts-11.2 script
{-# OPTIONS_GHC -Wall -W -Werror #-}
data Foo = Foo
{ fooInt :: Int
, fooBar :: Bar
} deriving Show
data Bar = Bar Baz
@vvv
vvv / DaPhone.hs
Created December 2, 2017 00:02
The Phone exercise from Chapter 11 of the Haskell book
{-# OPTIONS_GHC -Wall -Werror #-}
module DaPhone where
import Data.Char (isUpper, toLower)
import Data.List (elemIndex, foldl', intersperse)
import Data.Maybe (catMaybes)
data DaPhone = DaPhone [String]
deriving (Eq, Show)
@vvv
vvv / OrdEq.hs
Created September 7, 2017 10:54 — forked from mssawant/ordeq.hs
import Data.Foldable (foldl')
import Debug.Trace (trace)
prnEqual :: (Eq a) => a -> a -> IO ()
prnEqual a b = if a == b then print "True" else print "False"
-- Note the absence of parentheses around `Eq a` and having exactly one `print`.
prnEqual' :: Eq a => a -> a -> IO ()
prnEqual' a b = print $ if a == b then "True" else "False"
@vvv
vvv / misc.hs
Last active August 24, 2017 16:50 — forked from mssawant/misc.hs
Haskell exercise
{-- XXX Your definition of `checkChar` is okay, but the abstraction itself
-- is very odd. It is fine as an exercise of using "do" notation and
-- `return`. In real code though explicit statements are both short and
-- expressive (see lines 21-22).
checkChar :: IO Bool
checkChar = do
c <- getChar
return (c == 'y')
--}
listsum :: Num a => [a] -> a
listsum [] = 0
listsum (x:xs) = x + listsum xs
main :: IO ()
main = print $ listsum [1..5]
@vvv
vvv / Program.hs
Last active July 13, 2017 18:50
Working through the Operational Monad Tutorial
{-# LANGUAGE GADTs #-}
module Program where
--
-- The Operational Monad Tutorial:
-- http://apfelmus.nfshost.com/articles/operational-monad.html
--
-- GADT
data Program instr a where
Then :: instr a -> (a -> Program instr b) -> Program instr b
@vvv
vvv / noexit.sh
Last active August 29, 2015 14:27
Surprise of the day
$ cat noexit.sh
#!/bin/sh
seq 100 | while read; do exit; done # If `exit' terminated the script ..
echo 'Still alive!' # .. this message would not be printed.
$
$ sh noexit.sh
Still alive!
@vvv
vvv / gdb-m0ut-bt.sh
Last active August 29, 2015 14:25
gdb-m0ut-bt
#!/bin/sh
set -eu
M0UT=ut/.libs/lt-m0ut
[ -x $M0UT ] || { echo "$M0UT: No such file" >&2; exit 1; }
CORE=$(sudo ls -t $(sudo find /var/mero -type f -name core.\*) | head -1)
sudo gdb -nx -c $CORE $M0UT <<EOF
set pagination off