Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:50:56+00:00 2026-05-23T08:50:56+00:00

I’m attempting the Write Yourself a Scheme in 48 Hours tutorial and as someone

  • 0

I’m attempting the Write Yourself a Scheme in 48 Hours tutorial and as someone new to haskell it’s pretty difficult.
I’m currently working on a problem where I’m supposed to add the ability to parse scheme vectors (section 3.4 exercise 2).

I’m using this data type:

data LispVal = Atom String                  
         | List [LispVal]                   
         | Vector (Array Int LispVal)

To parse, I’m looking for ‘#(‘ then trying to parse the vector contents, drop them in a list and convert that list to an array.

I’m trying to use a list parsing function that I already have and am using but it parses scheme lists into the LispVal List above and I’m having a hard time getting that back into a regular list. Or at least that’s what I think my problem is.

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’s the list parser:

parseList :: Parser LispVal
parseList = liftM List $ sepBy parseExpr spaces

Any ideas on how to fix this?
Thanks,
Simon

-edit-
Here’s the compilation error I get:

Couldn’t match expected type a ->
LispVal'
against inferred type
Parser LispVal’ In the second argument of
(.)' namelyparseList’ In the second
argument of (.)' namely
lispValToList . parseList’ In the
expression: listToArray .
lispValToList . parseList

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:50:57+00:00Added an answer on May 23, 2026 at 8:50 am

    You do not provide lispValtoList but I suppose that it have the following type

    lispValtoList :: LispVal -> [LispVal]
    

    This would suggest the compiler to think that parseList is of type a -> LispVal. But it is not since it is Parser LispVal and so something like P String -> [(LispVal,String)].

    You have to extract the LispVal value that was parsed before putting it in a list.
    So parseVectorInternals must probably look like

    parseVectorInternals = do parsedList <- parseList 
                              let listOfLispVal = lispValtoList parsedList
                              return $ listToArray listOfLispVal
    

    You could write something more compact, but this code tries to be self-documented 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.