I am trying to write a diagram for myself in a 48-hour study guide and as someone new, to haskell is quite difficult. I am currently working on a problem where I must add the ability to analyze vector schemes (section 3.4, exercise 2).
I use this data type:
data LispVal = Atom String
| List [LispVal]
| Vector (Array Int LispVal)
For parsing, I search for '# (', then try to parse the contents of the vector, put them in a list, and convert this list into an array.
I'm trying to use the list parsing function that I already have and use it, but it parses the schema lists in the LispVal list above, and it's hard for me to return to the regular list. Or at least what I consider my problem.
lispValtoList :: LispVal -> [LispVal]
lispValtoList (List [a]) = [a]
parseVector :: Parser LispVal
parseVector = do string "#("
vecArray <- parseVectorInternals
char ')'
return $ Vector vecArray
parseVectorInternals :: Parser (Array Int LispVal)
parseVectorInternals = listToArray . lispValtoList . parseList
listToArray :: [a] -> Array Int a
listToArray xs = listArray (0,l-1) xs
where l = length xs
and here is the parser:
parseList :: Parser LispVal
parseList = liftM List $ sepBy parseExpr spaces
, ?
,
-edit-
, :
a ->
LispVal'
against inferred type Parser LispVal ' (.)' namely parseList ' (.)' namely lispValToList. parseList ' : listToArray. lispValToList. parseList