Skip to content

Commit

Permalink
[Feature:Autograding] Add Haskell image (#52)
Browse files Browse the repository at this point in the history
### Please check if the PR fulfills these requirements:

* [x] Tests for the changes have been added/updated (if possible)
* [x] Documentation has been updated/added if relevant

### What is the current behavior?
<!-- List issue if it fixes/closes/implements one using the "Fixes
#<number>" or "Closes #<number>" syntax -->
none

### What is the new behavior?
we can now run haskell files

### Other information?
<!-- Is this a breaking change? -->
<!-- How did you test -->
this is not a breaking change and I tested it using some simple files (I
included an example below):

```haskell
-- Function to compute the nth Fibonacci number
fibonacci :: Integer -> Integer
fibonacci n
  | n <= 0    = 0
  | n == 1    = 1
  | otherwise = fibonacci (n - 1) + fibonacci (n - 2)

-- Function to compute the factorial of a given number
factorial :: Integer -> Integer
factorial 0 = 1
factorial n = n * factorial (n - 1)

-- Function to check if a number is prime
isPrime :: Integer -> Bool
isPrime n
  | n <= 1    = False
  | n == 2    = True
  | otherwise = null [ x | x <- [2..isqrt n], n `mod` x == 0]
  where
    isqrt = floor . sqrt . fromIntegral

-- Main function to test the above functions
main :: IO ()
main = do
  putStrLn "Enter a number for Fibonacci calculation:"
  fibInput <- getLine
  let fibNumber = read fibInput :: Integer
  putStrLn ("Fibonacci number at position " ++ show fibNumber ++ " is " ++ show (fibonacci fibNumber))

  putStrLn "\nEnter a number for factorial calculation:"
  factInput <- getLine
  let factNumber = read factInput :: Integer
  putStrLn ("Factorial of " ++ show factNumber ++ " is " ++ show (factorial factNumber))

  putStrLn "\nEnter a number to check if it is prime:"
  primeInput <- getLine
  let primeNumber = read primeInput :: Integer
  putStrLn (show primeNumber ++ (if isPrime primeNumber then " is" else " is not") ++ " a prime number.")
```

---------

Co-authored-by: Chris Reed <[email protected]>
  • Loading branch information
ION606 and cjreed121 authored Oct 11, 2024
1 parent be77488 commit fc29263
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dockerfiles/haskell/8.8.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# First Stage: Builder
FROM ubuntu:22.04 AS builder

# Set the working directory
WORKDIR /usr/src/app

# Install libgmp-dev explicitly for runtime linking
RUN apt-get update \
&& apt search cabal-install \
&& apt-get install -y --no-install-recommends \
libgmp10 libtinfo5 build-essential libgmp-dev ghc=8.8.4-3 cabal-install=3.0.0.0-3build1.1 \
&& rm -rf /var/lib/apt/lists/*

# Default command to keep the container running
CMD ["/bin/bash"]

0 comments on commit fc29263

Please sign in to comment.