Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save sroccaserra/5e87391640921b38c700 to your computer and use it in GitHub Desktop.

Select an option

Save sroccaserra/5e87391640921b38c700 to your computer and use it in GitHub Desktop.
Fizzbuzz x Modoid x Elm
{-- Fizzbuzz sur un monoïde -----------------------
Ensemble : le sous-ensemble de Integerzz des éléments pour lesquels "fizzbuzz" est l'indentité.
Loi de composition interne : la fonction "pluzz".
Élément neutre : ("fizzbuzz", 0)
-----------------------------------------------------------}
import Graphics.Element exposing (..)
type alias Integerzz = (String, Int)
fizzbuzz : Integerzz -> Integerzz
fizzbuzz (_, x) =
if | x % 3 == 0 && x % 5 == 0 -> ("fizzbuzz", x)
| x % 3 == 0 -> ("fizz", x)
| x % 5 == 0 -> ("buzz", x)
| otherwise -> (toString x, x)
pluzz : Integerzz -> Integerzz -> Integerzz
pluzz (_, a) (_, b) =
fizzbuzz ("", a + b)
main : Element
main =
show <| pluzz ("8", 8) (pluzz ("1", 1) ("2", 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment