This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data FreeMonoid t | |
| = Zero | |
| | Combine t (FreeMonoid t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| myCoolFunction : Int -> Int | |
| myCoolFunction a = | |
| -- Calls the JS `addTwo` function. | |
| jsCall "addTwo" a | |
| main = | |
| myCoolFunction 3 | |
| |> String.fromInt | |
| |> Html.text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jsCall : String -> a | |
| jsCall funcName = | |
| jsCall funcName |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module FizzBuzz where | |
| data FizzResult | |
| = Val Int | |
| | Fizz | |
| | Buzz | |
| | FizzBuzz | |
| deriving (Show) | |
| divisibleBy :: Int -> Int -> Bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data FizzResult v pt pf rt rf | |
| = Val v pf rf | |
| | Fizz pt rf | |
| | Buzz pf rt | |
| | FizzBuzz pt rt | |
| deriving (Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |