/Functional_and_Logic_Programming

basic Functional and Logic Programming is haskell

Primary LanguageHaskell

Functional and Logic Programming in Haskell

This repository contains two homework assignments (hw1.hs and hw2.hs) related to functional and logic programming in Haskell. Each assignment includes a number of tasks implemented as Haskell functions.

Getting Started

  1. Clone this repository.
  2. Make sure you have a Haskell compiler installed (such as GHC, the Glasgow Haskell Compiler).

Assignments

hw1.hs

This Haskell script contains several functions showcasing basic functional programming concepts. These functions include:

  • shiftString: Shifts the characters in a string.
  • isShiftedForEquLessThanIterationTimes and isShifted: Checks if one string is a shifted version of another.
  • stupidListOp: Performs an operation on a list of integers.
  • getNextLine and pascalLine: Generates a line of Pascal's Triangle.
  • toList, padWithZero, toDigits, doubleEveryOther, sumDigits, validate: Implements various operations related to the validation of credit card numbers.

hw2.hs

This Haskell script continues to explore functional programming concepts with a different set of functions. These include:

  • makeDistinctInt and makeDistinctString: Removes duplicate items from a list.
  • multiplyLists: Multiplies items in a list.
  • listSquares and roundSquare: Deals with square numbers.
  • twoSqaures: Finds two squares that sum up to a given prime number.
  • slowSort: Sorts a list of integers.

Running the Scripts

To run the Haskell scripts, follow these steps:

  1. Open a terminal.
  2. Navigate to the directory containing the Haskell script you want to run.
  3. Compile the script using the GHC compiler with the command ghc --make script_name.hs (replace script_name.hs with the name of the script).
  4. Run the compiled file using the command ./script_name (replace script_name with the name of the script without the .hs extension).

Contributing

This is an academic project, and contributions are not currently sought. However, the scripts provided can serve as a foundation for anyone interested in learning functional and logic programming in Haskell.

License

This project is licensed under the terms of the MIT license. Please refer to the LICENSE file for more information.