Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
@quephird
quephird / HelloGlsl.purs
Last active August 5, 2016 02:14
Trying to get a minimal example of GLSL in PureScript
module Example.HelloGlsl where
import Prelude (Unit(..)
,($)
,bind)
import Control.Monad.Eff (Eff(..))
import Control.Monad.Eff.Alert (Alert(..)
,alert)
import Control.Monad.Eff.Console (CONSOLE(..)
@quephird
quephird / FilterM.purs
Created September 5, 2015 21:52
Solution to exercise 5 in section 8.7 in PureScript by Example
module FilterM where
import Prelude (Monad, ($), (<), (>), (/=), bind, return)
import Data.List (List(..))
import Data.Maybe (Maybe(..))
filterM' :: forall m a. (Monad m) => (a -> m Boolean) -> List a -> List a -> m (List a)
filterM' p acc Nil = return acc
filterM' p acc (Cons x xs) = do
@quephird
quephird / Sums.purs
Last active September 4, 2015 20:31
Solution to exercise 2 in section 8.7 in PureScript by Example
module Sums where
import Data.Array ((:), foldM, nub, sort)
import Data.Maybe (Maybe(..))
import Prelude (($), (+), (++), map)
-- Given an array of integers, compute the list of all
-- possible totals, using each integer at most once.
sums :: Array Int -> Maybe (Array Int)
@quephird
quephird / Pi.purs
Last active September 3, 2015 22:39
Solution to exercise in PureScript by Example book to estimate pi
module Pi where
import Control.Monad.Eff (Eff(..), forE)
import Control.Monad.Eff.Random (RANDOM(..), random)
import Control.Monad.ST (ST(..), modifySTRef, newSTRef, readSTRef)
import Data.Array ((:), filter, length)
import Data.Int (toNumber)
import Data.Tuple (Tuple(..))
import Prelude (($), (<=), (+), (*), (/), bind, return, unit)
@quephird
quephird / aaarrrggghhh.elm
Last active August 29, 2015 14:24
This is a rewrite of the example chapter 2 of Elm by Example that is compatible with Elm 0.15 and 2.1.0 of the core libraries.
module Fibonacci where
import List exposing ((::), head, map2, reverse, tail)
import Maybe exposing (andThen)
fibonacci : Int -> List Int
fibonacci n =
let fibonacci' n acc =
if n <= 2
then acc
╭ ◜ ◝ ͡ ◝ ͡ ◜ ◝ ╮
(fill in here)
╰ ͜ ╯
O
o
°
〃∩ ∧_∧ 💕
⊂⌒( ´・ω・)💕
`ヽ_っ_/ ̄ ̄ ̄/
    \/___/
splitWith :: (a -> Bool) -> [a] -> [[a]]
splitWith p l
| null l = []
| null xs = splitWith p $ tail xs'
| otherwise = xs : splitWith p xs' where
(xs, xs') = break p l
@quephird
quephird / TransposeFile.hs
Last active August 29, 2015 14:19
Using the supplied interactWith function, write another function that transposes the file contents of the input and writes it to another file.
interactWith :: (String -> String) -> FilePath -> FilePath -> IO ()
interactWith f inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (f input)
transpose = unlines . transpose' . lines where
transpose' ss | all ((==) "") ss = []
transpose' ss = map head nonEmptySs : (transpose' $ map tail nonEmptySs) where
nonEmptySs = filter ((/=) "") ss
@quephird
quephird / writeFirstWords.hs
Created April 12, 2015 03:17
Using the supplied interactWith function, write another function that writes the first word of each line to another file.
interactWith :: (String -> String) -> FilePath -> FilePath -> IO ()
interactWith f inputFile outputFile = do
input <- readFile inputFile
writeFile outputFile (f input)
writeFirstWords inputFile outputFile = interactWith firstWords inputFile outputFile where
firstWord "" = ""
firstWord line = head $ words line
firstWords file = unlines $ map firstWord $ lines file
@quephird
quephird / Mabes.hs
Created April 7, 2015 23:52
Solution to Alej's exercise
{- |
Fill in the Blank: Meet Mabes - the other Maybe type.
This exercise is all about defining common abstraction over Mabes, e.g.:
* Functor
* Applicative
* Monad
* Alternative