Command line Haskell: Running function from main.hs

Viewed 176

My program is made up of three parts: Machine, Interpreter, and Compiler.

It doesn't really matter what each one does, I'm sure you could guess though. What matters is that there is a function in Compiler.hs that returns a list of Instr (which is a data type I defined in Machine). This function is called ccomp, which takes a Com type as input (a data type I defined in Interpreter).

ccomp :: Com -> [Instr]

ccomp (Assign v x) = acomp(x) ++ [STORE v]
ccomp (Seq c1 c2) = ccomp (c1) ++ ccomp (c2)

My next task is to write a main function that allows the ccomp function to be run from the command line using stack exec project-exe "Assign \"x \" (Plus (N 5) (N 3))"

The code above runs the main.hs file with the String between quotes as an argument. The problem is I can't figure out what to put in the main function:

module Main where

import System.Environment
import Compiler

main :: IO ()
main = do
       args <- getArgs
       putStrLn (ccomp(head(args))) 

This doesn't work, the expected type for ccomp is Interpreter.Com and it receives a String. I've tried changing the type using read, but that didn't work as the Com constructor was not in scope.

Is there a simple way of passing the command line argument into the ccomp function that I'm missing?

0 Answers
Related