Created
August 8, 2014 11:01
-
-
Save erochest/d673e3b6bce5d45adac9 to your computer and use it in GitHub Desktop.
Trying to parse out http://www.reddit.com/r/haskell/comments/2cum9p/i_did_a_haskell_fizzbuzz/cjjwzkm in the repl
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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# OPTIONS_GHC -Wall #-} | |
{-# OPTIONS_GHC -fno-warn-orphans #-} | |
module FizzBuzz where | |
import Control.Applicative | |
import Data.Maybe | |
import Data.Monoid | |
instance Monoid a => Monoid (ZipList a) where | |
mempty = pure mempty | |
mappend = liftA2 mappend | |
(>~) :: forall (f :: * -> *) a. (Monoid (f a), Applicative f) | |
=> Int -> a -> ZipList (f a) | |
m >~ a = ZipList . cycle $ replicate (m - 1) mempty ++ [pure a] | |
fizzbuzz :: [String] | |
fizzbuzz = getZipList $ fromMaybe . show <$> ZipList [(1 :: Int)..] <*> 3 >~ "fizz" <> 5 >~ "buzz" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment