Skip to content

Instantly share code, notes, and snippets.

@FrigoEU
FrigoEU / SketchSystems.spec
Last active September 13, 2018 12:17
Pretty Printing Ur
Pretty Printing Ur
Ur Definition Rules
val -> Ur Expression Rules
fun so align arguments and result -> Ur Expression Rules
comments -> Comment Rules
Ur Expression Rules
let -> Let Binding Rules
case of so pretty print -> Ur Expression Rules
Open angular brackets -> XML Tag Rules
Open Xml Tags -> XML Content Rules
@FrigoEU
FrigoEU / SketchSystems.spec
Last active August 30, 2018 11:11
Parsing CSV
Parsing CSV
New Line*
EOF -> Done
Not EOF -> Reading Field
Reading Field
EOF -> Not Quoted
First character is quote -> Quoted
First character is not quote -> Not Quoted
Quoted
Read till next quote and use as value -> After Quoted
@FrigoEU
FrigoEU / SketchSystems.spec
Last active August 17, 2018 09:55
Import Screen
Import Screen
Not Yet Imported*
Initial
import is ok -> Imported
wrong format -> Display Error
Display Error
import is ok -> Imported
wrong format -> Display Error
Imported
No Errors
@FrigoEU
FrigoEU / 24days.md
Last active December 11, 2016 16:04
24 days of PureScript

Getting good error messages when the compiler rejects your program is very important for the day to day usability of a language. In an attempt to allow library authors to help out with this and generate better error messages for their users, the ability to define "Fail" instances for typeclasses was added to the compiler in v0.9.1. When a user of a typeclass tries to use one of these instances, the compiler will throw a custom error. Which error depends on how you define your Fail instance. For example:

module Main where

import Prelude
import Control.Monad.Eff.Console (log)

class Serialize a where
 serialize :: a -> String
@FrigoEU
FrigoEU / Main.purs
Last active December 21, 2016 18:07
Poly labels wih Fail instance
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
import Data.Newtype (class Newtype, unwrap)
import Data.Profunctor (dimap)
import Data.Profunctor.Strong (class Strong, second)
import Data.Tuple (Tuple(..), uncurry)
import Type.Proxy (Proxy(..))
@FrigoEU
FrigoEU / Main.purs
Last active December 11, 2016 09:28
Fail Instance with TypeString/TypeConcat
module Main where
import Prelude
import Control.Monad.Eff.Console (log)
class Serialize a where
serialize :: a -> String
instance cannotSerializeFunctions
:: Fail ("Cannot serialize the function: " <> TypeString (a -> b) <> ". Functions can't be serialized.")
@FrigoEU
FrigoEU / Main.purs
Last active December 11, 2016 09:28
Fail Instance without TypeString/TypeConcat
module Main where
import Prelude
import Control.Monad.Eff.Console (log)
class Serialize a where
serialize :: a -> String
instance cannotSerializeFunctions
:: Fail ("Cannot serialize functions.")
@FrigoEU
FrigoEU / lovefield.purs
Created November 13, 2016 23:26
Fun Deps for SQL
module Lovefield where
import Data.Array (snoc)
import Data.Foreign (Foreign)
import Data.Lens (Lens, lens)
import Data.Tuple (Tuple(..))
import Prelude (class Show, show, (#), ($), (<>), (>>>))
-- Your implementation of polymorphic labels starts here
data Label (l :: Symbol) = Label
manyMaybe :: forall m a. (Monad m) => ParserT String m a -> ParserT String m (Array a)
manyMaybe p = mapMaybe id <$> many (maybeP p)
maybeP :: forall m a. (Monad m) => ParserT String m a -> ParserT String m (Maybe a)
maybeP p = choice [(Just <$> p), (anyChar *> return Nothing)]
url :: URL
arr = [maybe mempty (\o -> Node.SimpleRequest.host := o) (toMaybe url.host), ...]
opt = foldMap id arr