From 398f0517ef12917309b8bc3dcb9d04497feead2a Mon Sep 17 00:00:00 2001 From: Lahari Date: Mon, 13 Jan 2025 17:03:15 +0530 Subject: [PATCH] Added Haskell and SML programs for fibonacci sequence --- Contributors.md | 1 + Languages.md | 2 ++ fibonacci_series/Haskell/Haskell_fibonacci.hs | 8 ++++++ fibonacci_series/SML/SML_fibonacci.sml | 27 +++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 fibonacci_series/Haskell/Haskell_fibonacci.hs create mode 100644 fibonacci_series/SML/SML_fibonacci.sml diff --git a/Contributors.md b/Contributors.md index 30191bc..b34a353 100644 --- a/Contributors.md +++ b/Contributors.md @@ -14,3 +14,4 @@ shravan20 Avatar bettman-latin MrJithi +Lahari diff --git a/Languages.md b/Languages.md index aef5d76..0db761d 100644 --- a/Languages.md +++ b/Languages.md @@ -14,6 +14,7 @@ Hello there!! - C++ - Dart - Go +- Haskell - Java - Javascript - Kotlin @@ -27,4 +28,5 @@ Hello there!! - Rust - Scala - Scheme +- SML - Typescript diff --git a/fibonacci_series/Haskell/Haskell_fibonacci.hs b/fibonacci_series/Haskell/Haskell_fibonacci.hs new file mode 100644 index 0000000..21d3a7a --- /dev/null +++ b/fibonacci_series/Haskell/Haskell_fibonacci.hs @@ -0,0 +1,8 @@ +fibonacci :: Integer -> [Integer] +fibonacci n = map fst $ take (fromIntegral n) $ iterate (\(a, b) -> (b, a + b)) (1, 1) + +main = do + putStrLn "Enter the number of Fibonacci terms to be printed" + input <- getLine + let n = read input :: Integer + putStrLn (show (fibonacci n)) diff --git a/fibonacci_series/SML/SML_fibonacci.sml b/fibonacci_series/SML/SML_fibonacci.sml new file mode 100644 index 0000000..433db3a --- /dev/null +++ b/fibonacci_series/SML/SML_fibonacci.sml @@ -0,0 +1,27 @@ +local + fun fibonacci (i:IntInf.int, j:IntInf.int, n:IntInf.int ) = + let + fun fib (a,b,0) = [] + | fib (a,b,count) = a::fib(b,a+b,count-1) + in + fib (i,j,n) + end + + fun printList [] = () + | printList (x::[]) = print (IntInf.toString x ^ "\n") + | printList (x::xs) = (print (IntInf.toString x ^ ", "); printList xs) + + fun main () = + let + val _ = print "Enter the number of Fibonacci numbers to be printed: " + val input = TextIO.inputLine TextIO.stdIn + val n = valOf (IntInf.fromString (valOf input)) + + val result = fibonacci (IntInf.fromInt 1,IntInf.fromInt 1,n) + val _ = printList result + in + () + end +in + val _ = main() +end \ No newline at end of file