Hey,
I have been trying to program a simple Haskell program that allows me to input a list of Java files and their dependencies (i.e. other files which they rely upon) and have come across some very stubborn problems.
> semiColon :: Char -> Bool
> semiColon ':' = True
> semiColon _ = False
> getFDepend :: String -> String
> getFDepend file = reverse(stripEX(reverse(fst(break semiColon file))))
> getDepends :: String -> [String]
> getDepends depend = words(stripEX(snd(break semiColon depend)))
> getArray :: [String] -> [File]
>getArray [a]
> | length[a] == 1 = [parseFile (head[a])]
> | otherwise = [parseFile (head[a])] && (getArray (tail[a]))
> -- WRITE parseDependency, 12 marks
> parseDependency :: String -> Dependency
> parseDependency ds = (Dependency (parseFile(getFDepend(ds))) [getArray(getDepends ds)])
> fullStop :: Char -> Bool
> fullStop '.' = True
> fullStop _ = False
Removes leading whitespace and fullstops
> stripEX :: String -> String
> stripEX [] = []
> stripEX (a:ab)
> | isSpace a = stripEX ab
> | fullStop a = stripEX ab
> | semiColon a = stripEX ab
> | otherwise = (a:ab)
Gets the filename
> getFirst :: String -> String
> getFirst filename = fst (break fullStop filename)
Gets the unformated extension
> formatLast :: String -> String
> formatLast ext = snd (break fullStop ext)
Formats the extension
> getLast :: String -> String
> getLast ext = stripEX(reverse (stripEX (reverse (formatLast(ext)))))
> parseFile :: String -> File
> parseFile name = File { basename = (getFirst(name)), ext = classifyExtension(getLast(name)) }
For some reason my getArray function keeps kicking up a program. I am unsure if I have done this correctly. What I was aiming to do was take a List of strings ("A.java", "B.java") and create a File type for each of them, then add this to an array which would be returned at the end.
Anyone know a better method or what is wrong?
-Mike