Skip to content

Instantly share code, notes, and snippets.

module ParseFull where
import Control.Applicative
import Data.Char
newtype Parser a = P (String -> [(a,String)])
parse :: Parser a -> String -> [(a,String)]
parse (P p) inp = p inp
item :: Parser Char
module ShowExpression where
data Op = Add | Sub | Mul | Div
instance Show Op where
show Add = "+"
show Sub = "-"
show Mul = "*"
show Div = "/"
@varreli
varreli / gist:13eb5adcddc52ae87847156389b0f5e1
Last active May 17, 2018 19:05
variation of function choices
import Debug.Trace
subs :: [a] -> [[a]]
subs [] = [[]]
subs (x:xs) = yss ++ map (x:) yss
where yss = subs xs
interleave :: a -> [a] -> [[a]]
interleave x [] = [[x]]
interleave x (y:ys) = (x:y:ys) : map (y:) (interleave x ys)
module ShowExpression where
data Op = Add | Sub | Mul | Div
instance Show Op where
show Add = "+"
show Sub = "-"
show Mul = "*"
show Div = "/"
import ShowExpression
subs :: [a] -> [[a]]
subs [] = [[]]
subs (x:xs) = yss ++ map (x:) yss
where yss = subs xs
interleave :: a -> [a] -> [[a]]
interleave x [] = [[x]]
split :: [a] -> [([a], [a])]
split [] = []
split [_] = []
split (x:xs) = ([x], xs) : [(x:ls, rs) | (ls, rs) <- split xs]
-- auxillary function combine in exprs:
combine :: Expr -> Expr -> [Expr]
combine l r = [App o l r | o <- ops]
~/haskell/hutton]
$ ls
001_math 28_and_all.hs 59_chapt7.hs
002_notes 29_recurse.hs 59_chapt7i.hs
01_qsort.hs 30_merge.hs 60_redefines.hs
02_last.hs 31_mergeSample.hs 61_iterate.hs
03_init.hs 32_mSort.hs 62_parity.hs
04_abs.hs 33_core.hs 63_parity2.hs
05_twice.hs 34_core.hs 64_altMap.hs
06_patMatch.hs 35_basicMap.hs 65_luhn.hs
λ > :l 75_taut.hs
[1 of 1] Compiling Main ( 75_taut.hs, interpreted )
75_taut.hs:2:1: error:
Failed to load interface for ‘Propositions’
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
λ >
@varreli
varreli / gist:7e3e9b158a399087c0c31d236dde82ee
Created June 1, 2017 00:49
also having trouble with stack
I'm running $ stack build primality now , and getting the same very slow process that I got for $ stack new primality:
~/haskell $ stack new primality
Downloading template "new-template" to create project "primality" in primality/ ...
The following parameters were needed by the template but not provided:
author-email, author-name, category, copyright, github-username
You can provide them in /home/john/.stack/config.yaml, like this:
templates:
params:
@varreli
varreli / gist:6ed319b53132e4dbab98f82e64801aac
Created June 1, 2017 00:32
terminal output of installation of vim and haskell-vim-now
~ $ sudo apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
vim-doc vim-scripts
The following NEW packages will be installed:
vim
0 upgraded, 1 newly installed, 0 to remove and 316 not upgraded.
Need to get 0 B/976 kB of archives.