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

  • Home
  • SEARCH
  • 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 8614135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:03:07+00:00 2026-06-12T05:03:07+00:00

The Issue is to input two lists and repeat the elements in first list

  • 0

The Issue is to input two lists and repeat the elements in first list according the corresponding number in other list.
e.g. repeat([2,3,4],[1,2,2]) would give [2,3,3,4,4]

fun repeat1(a,b)=if b>0 then a::repeat1(a,b-1) else [];
fun repeat([],[])=[]
|repeat([l1],[m1])=repeat1(l1,m1)
|repeat(l1::ln,m1::mn)=if length(l1::ln)=length(m1::mn) then if ln<>[] then repeat1(l1,m1)@repeat(ln,mn) else [] else []; 

The error says

stdIn:36.64-36.66 Warning: calling polyEqual
stdIn:34.5-36.112 Warning: match nonexhaustive
          (nil,nil) => ...
          (l1 :: nil,m1 :: nil) => ...
          (l1 :: ln,m1 :: mn) => ...

What are these for (I know its for base cases and inductive cases are not sufficient)? But how do I remove this warning even though this does not effect the output of the program?. Thanks.

  • 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-06-12T05:03:08+00:00Added an answer on June 12, 2026 at 5:03 am

    You obviously forgot two base cases when only one in two lists is empty. Since these cases are malformed inputs, you can use exception to handle them:

    exception LengthNotEqual
    
    fun repeat ([], []) = []
      | repeat ([], _) = raise LengthNotEqual
      | repeat (_, []) = raise LengthNotEqual
      | ...
    

    After adding two new base cases, you don’t need to compare lengths of two lists in the last pattern anymore. The use of length should be avoided since it will traverse the whole list once more. And the pattern ([l1], [m1]) could be removed due to redundancy.

    So the new repeat function looks like:

    fun repeat ([], []) = []
      | repeat ([], _) = raise LengthNotEqual
      | repeat (_, []) = raise LengthNotEqual
      | repeat (l1::ln, m1::mn) = repeat1(l1, m1)@repeat(ln, mn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue where input is being doubled, tripled, quadrupled, etc. on user
I have run into an issue where an input field within a form I'm
I'm having an issue with the date input from jQuery Tools. When I click
Hello I'm having an issue with this check box : <input type=checkbox id=hideTempSeries checked=checked
can't find solution to this issue. So i have datepicker input field, it works
Hello folks, I've got the issue to add a browser event to some input
I have an issue with a table containing three cells in one row. Two
I have two input components on my page . Each of them has a
I'm trying to make a program that gets two input numbers, multiplies them (storing
my issue is that i have two ajax calls to php for a registration

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.