evgenyigumnov / rustsn

Code snippets generator via LLMs and compiler/tester via build tools
GNU General Public License v3.0
18 stars 5 forks source link

Add Haskell support #14

Open evgenyigumnov opened 2 days ago

evgenyigumnov commented 2 days ago

Launch example

rustsn --lang=haskell

Example query:

take 2 params and add them and return result

Example generation:

package.yaml

name: solution
version: 0.1.0.0
description: Minimalistic Haskell project
author: ""
license: ISC
dependencies:
  - base >= 4.7 && < 5
  - hspec >= 2.7
library:
  source-dirs: src
  exposed-modules: Solution
  ghc-options: -Wall
test-suite solution-test
  type: exitcode-stdio-1.0
  main: Spec.hs
  hs-source-dirs: test
  build-depends:
    - base
    - hspec
    - solution
  ghc-options: -Wall

src/Solution.hs

module Solution (solution) where

solution :: Num a => a -> a -> a
solution a b = a + b

test/Spec.hs

import Test.Hspec
import Solution

main :: IO ()
main = hspec $ do
  describe "solution" $ do
    it "adds 1 and 2 to get 3" $
      solution 1 2 `shouldBe` 3

    it "adds (-1) and (-2) to get (-3)" $
      solution (-1) (-2) `shouldBe` (-3)

    it "fails when adding a non-numeric type" $
      -- Haskell is strongly typed; attempting to add incompatible types results in a compile-time error
      pendingWith "Haskell does not allow adding a String and an Int"

Example install dependencies

stack setup
stack build

Example launch compilation

stack build

Example launch test

stack test

Project Structure:

haskell/
├── logic.md
├── prompt.txt
├── package.yaml
├── src
│   └── Solution.hs
├── test
│   └── Spec.hs
└── stack.yaml