Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
---- Put it together and show it ----
main = lift3 presentation sunAndEarth bouncingBall sineGraph
presentation figure1 figure2 f3 =
flow down [ figure1, figure2, f3 ]
-- Signal.foldp : (a -> b -> b) -> b -> Signal a -> Signal b
@pedrofurla
pedrofurla / gist:8088366
Created December 22, 2013 20:58
Is Misty ((->) t) banana right?
class Misty m where
banana :: (a -> m b) -> m a -> m b
unicorn :: a -> m a
-- Exercise 6
-- Relative Difficulty: 3
-- (use banana and/or unicorn)
furry' :: (a -> b) -> m a -> m b
furry' = banana . (unicorn .)
instance Misty ((->) t) where
@pedrofurla
pedrofurla / gist:8222095
Created January 2, 2014 16:44
Nicta course types summary
data Id a
runId :: Id a -> a
mapId :: (a -> b) -> Id a -> Id b
bindId :: (a -> Id b) -> Id a -> Id b
data List t = Nil | t :. (List t)
infinity :: List Integer
foldRight :: (a -> b -> b) -> b -> List a -> b
foldLeft :: (b -> a -> b) -> b -> List a -> b
@pedrofurla
pedrofurla / gist:8231743
Created January 3, 2014 02:49
Apply (State s) is confusing to the extreme ... my variable names doesn't help either
instance Apply (State s) where
-- Apply f ⇒ (<*>) :: f (a -> b) -> f a -> f b
-- Apply (State s) ⇒ (<*>) :: State s (a -> b) -> State s a -> State s b
--sab <*> sa = (\f → f <$> sa) <$> sab
sab <*> sa =
let
fsab = runState sab -- ∷ s → (a → b, s)
fsa = runState sa -- ∷ s → (a, s)
apply s =
let
@pedrofurla
pedrofurla / Macros.scala
Created January 11, 2014 20:38
Example of how to get source locations using scala macros
package slickdemo
import scala.reflect.macros.Context
import scala.language.experimental.macros
object Macros {
// scala.reflect.runtime.currentMirror
// universe.reify
@pedrofurla
pedrofurla / gist:8414258
Created January 14, 2014 06:59
Is this impl so wrong?
instance Apply MaybeListZipper where
(IsZ l) <*> (IsZ r) = IsZ $ l <*> r
_ <*> _ = IsNotZ
Build FAILED
/Users/pedrofurla/dev/projects/nicta-fp-course/src/Course/ListZipper.hs: line 605, column 31:
Ambiguous occurrence `<*>'
It could refer to either `Course.ListZipper.<*>',
@pedrofurla
pedrofurla / gist:8467057
Created January 17, 2014 01:42
error "todo" is special? `in` can contain statements?
hardCoreFunction a b c =
let z = a + b
k = b + c
in
error "todo" -- should be removed when the code below is not comment
z + k -- these are only experiements, usually explorations into the types of z and k
@pedrofurla
pedrofurla / parser-snippet.hs
Created January 17, 2014 02:03
Not sure I am completely degenerating Parser.hs or providing improvement. I found a lot easier to work with these combinator
toParserList :: Parser a -> Parser (List a)
toParserList = bindParser (\i -> valueParser (i:.Nil))
concatParser :: Parser (List t) -> Parser (List t) -> Parser (List t)
concatParser (P p1) (P p2) =
P(\i -> withResultInput (\i2 a2 -> withResultInput (\i3 a3 -> Result i3 $ a2 ++ a3) $ p2 i2 ) $ p1 i)
(~~~) ::
Parser t
-> Parser t
@pedrofurla
pedrofurla / Parsers-snippet.hs
Last active January 3, 2016 23:19
Some convenience combinators for Parser.hs and personParser. Suggestions and critiques are welcome.
sequenceParser ::
List (Parser a)
-> Parser (List a)
sequenceParser ps =
let
in foldRight (~~<) (valueParser Nil) ps
-- combinators for easily "appending" parsers
@pedrofurla
pedrofurla / example.js
Created January 23, 2014 07:12
Mapping from source JS (generated from .scala) to the actual Scala source(s)
ScalaJS.impls.example_WebAudio$AudioParam$class__$init$__Lexample_WebAudio$AudioParam__V = (function($this) {
$this.value_$eq__Lscala_scalajs_js_Number__V(ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing());
$this.example$WebAudio$AudioParam$_setter_$defaultValue_$eq__Lscala_scalajs_js_Number__V(ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing())
});
ScalaJS.impls.example_WebAudio$GainNode$class__$init$__Lexample_WebAudio$GainNode__V = (function($this) {
$this["example$WebAudio$GainNode$_setter_$gain"] = ScalaJS.modules.scala_Predef().$qmark$qmark$qmark__Lscala_Nothing()
});
/** @constructor */