Last active
March 14, 2016 16:16
-
-
Save AphonicChaos/869f6f987c72de4208fa to your computer and use it in GitHub Desktop.
What happens when I try to make Haskell look like F#
This file contains 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 FSharp where | |
import Text.Printf | |
import Prelude hiding ((.)) | |
(%) :: Integral a => a -> a -> a | |
(%) = mod | |
(.) :: a -> (a -> b) -> b | |
x . f = f x | |
(|>) :: a -> (a -> b) -> b | |
(|>) = (.) | |
toString :: () -> Int -> String | |
toString () = show | |
printfn :: PrintfType r => String -> r | |
printfn = printf |
This file contains 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 List | |
( iter | |
, L.map | |
) where | |
import qualified Data.List as L | |
import qualified Control.Monad as M | |
import Prelude hiding ((.)) | |
import Data.Foldable () | |
iter :: (Foldable t, M.Monad m) => (a -> m b) -> t a -> m () | |
iter = M.mapM_ |
This file contains 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
let main = | |
[1..100] | |
|> List.map (fun x -> | |
match x with | |
| _ when x % 15 = 0 ->"fizzbuzz" | |
| _ when x % 5 = 0 -> "buzz" | |
| _ when x % 3 = 0 -> "fizz" | |
| _ -> x.ToString()) | |
|> List.iter (fun x -> printfn "%s" x) |
This file contains 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 Main where | |
import qualified List | |
import FSharp | |
import Prelude hiding ((.)) | |
main = | |
[1..100] | |
|> List.map (\x -> | |
case () of | |
_ | x % 15 == 0 -> "fizzbuzz" | |
_ | x % 5 == 0 -> "buzz" | |
_ | x % 3 == 0 -> "fizz" | |
_ -> x.toString()) | |
|> List.iter (\x -> printfn "%s" x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kids, don't do this at home. A lot of the code in the Haskell variant is redundant and uneccessary, but I wanted to be as true to the original FSharp variant. If I were doing this in idiomatic Haskell, I might just pass
putStrLn
toControl.Monad.forM_
.