Skip to content

Instantly share code, notes, and snippets.

View dgendill's full-sized avatar

Dominick Gendill dgendill

View GitHub Profile
@dgendill
dgendill / Connection.purs
Last active March 1, 2017 21:35
An example of how to use `loop` in the purescript-coroutines library for a single producer and consumer, and for multiple consumers connected to a single producer
module Connection where
import Prelude
import Control.Coroutine (Consumer, Producer, await)
import Control.Coroutine.Aff (produceAff)
import Control.Monad.Aff (Aff, later')
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Aff.Console (CONSOLE, log)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Random (RANDOM, randomInt)
@dgendill
dgendill / AffParallelExample.purs
Last active February 24, 2017 21:53
An example of using Aff to run synchronous and asynchronous effects, and how to sequentially group effects using parSequence.
-- Run with `pulp run --main AffParallel`
module AffParallelExample where
import Prelude
import Control.Monad.Aff (Aff, launchAff, forkAll, later')
import Control.Monad.Console (Console, log)
import Control.Parallel (parSequence)
type Piece = String
@dgendill
dgendill / Main.purs
Last active May 11, 2017 13:20
Example using the Writer monad's listen, past, and listens functions in PureScript. Also exercise 11.6 part 2
-- http://try.purescript.org/?gist=45bfcac3cf142daaa165323ae45069cd
module Main where
import Prelude
import Control.Monad.Writer(Writer(..), tell, listen, listens, pass, runWriter)
import Data.Array(tail, head, drop, length)
import Data.String(joinWith)
import Data.Tuple(fst, snd, Tuple(..))
import Math (remainder, (%))
import Control.Monad.Eff.Console (log, logShow)
@dgendill
dgendill / Main.purs
Last active January 4, 2018 16:51
Example of the State and Either Monad used in Purescript
-- http://try.purescript.org/?gist=8edc7ff9f3f3bcd347959e9cd2f07376
module Main where
import Prelude
import Data.Identity
import Control.Monad.State
import Control.Monad.Except
import Control.Monad.Eff.Console (log, logShow)
type FirstName = String
@dgendill
dgendill / bailed-stack-overflow-question1.markdown
Last active April 17, 2016 17:16
Why does this Show instance throw "Count not match a0 with type String" (Purescript)

Why does this Show instance throw "Count not match a0 with type String" (Purescript)

Question

I'm working with this custom data type, and I would to be able to show it if the type of a is showable.

data NonEmpty a = NonEmpty a (Array a)

So I created this type class instance with the dependency that a be showable...

@dgendill
dgendill / 01-purescript-blanks-slate.purs
Last active April 2, 2016 17:52
This is a blank starting point for working with PureScript. It can pasted into http://try.purescript.org/ as a starting point for the exercises on PureScript by Example https://leanpub.com/purescript/read
module Main where
import Prelude
import Data.Array (replicate)
import Data.String (length, fromCharArray)
import Data.Foldable (for_)
import Control.Monad.Eff
import Control.Monad.Eff.Console (log, print)