Skip to content

Instantly share code, notes, and snippets.

View jjant's full-sized avatar
馃挜

Julian Antonielli jjant

馃挜
View GitHub Profile
@jjant
jjant / FreeMonoidDataType.hs
Created September 9, 2018 19:36
FreeMonoid implementation
data FreeMonoid t
= Zero
| Combine t (FreeMonoid t)
myCoolFunction : Int -> Int
myCoolFunction a =
-- Calls the JS `addTwo` function.
jsCall "addTwo" a
main =
myCoolFunction 3
|> String.fromInt
|> Html.text
jsCall : String -> a
jsCall funcName =
jsCall funcName
var author$project$Main$jsCall = function (str) {
jsCall:
while (true) {
var $temp$str = str;
str = $temp$str;
continue jsCall;
}
};
var author$project$Main$jsCall = function (str) {
return window[str];
};
@jjant
jjant / FizzBuzz.hs
Last active November 10, 2018 23:40
module FizzBuzz where
data FizzResult
= Val Int
| Fizz
| Buzz
| FizzBuzz
deriving (Show)
divisibleBy :: Int -> Int -> Bool
data FizzResult a
= Val a
| Fizz
| Buzz
| FizzBuzz
deriving (Show)
mkFizzBuzz :: (a -> Bool) -> (a -> Bool) -> a -> FizzResult a
mkFizzBuzz p r a =
case (p a, r a) of
data FizzResult v pt pf rt rf
= Val v pf rf
| Fizz pt rf
| Buzz pf rt
| FizzBuzz pt rt
deriving (Show)
mkFizzBuzz :: (v -> Either pf pt) -> (v -> Either rf rt) -> v -> FizzResult v pt pf rt rf
mkFizzBuzz p1 p2 v =
case (p1 v, p2 v) of
(Right pt, Right rt) -> FizzBuzz pt rt
(Right pt, Left rf) -> Fizz pt rf
(Left pf, Right rt) -> Buzz pf rt
(Left pf, Left rf) -> Val v pf rf
@jjant
jjant / FB.hs
Created November 11, 2018 00:28
-- We don't really care about the types pt, pf, rt and rf here,
-- and we want to get an Int back when both predicates are false.
type FizzBuzz = FizzResult Int () () () ()
-- Helper function to format predicates to the form mkFizzBuzz needs.
boolToEither :: Bool -> Either () ()
boolToEither True = Right ()
boolToEither False = Left ()
fizzbuzz :: Int -> FizzBuzz