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 8671135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:52:31+00:00 2026-06-12T18:52:31+00:00

Hi all im new to programming and im doing a problem for learning and

  • 0

Hi all im new to programming and im doing a problem for learning and enjoyment. Im a bit stuck at this point.. The problem is from Introduction to Programming using Sml 5.9

I want to split a list of [x1, x2, x3, ... ,xn] = ([x1, x3,....], [x2, x4,...])

This is what I have made so far:

fun split [] =  []
  | split (x1::x2::x3::x4::xs) = ([x1, x3], [x2, x4])::split xs



val test1split = split [1, 1, 2, 3];

From this I get:

[([1, 2], [1, 3])]…. (I want a tuple with splitting list and not this obviously)

If there are more than 4 elements then the function doesn’t work. Maybe I need a helper function to sort even and odd elements in a list first? I hope someone can help me with tracking my mind in the correct direction, until then I keep trying.

  • 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-12T18:52:32+00:00Added an answer on June 12, 2026 at 6:52 pm

    I’ll try not to give too much away, but here are some tips:

    • You need two base cases – one for [], one for [x].
    • Your general case only needs to deal with two elements, not four (putting one in the first list, and one in the second)
    • At the moment, you’ve got split returning a list, rather than a tuple. The result of your first base case should be ([],[]).
    • In the general case, the recursive split xs will return a tuple (ys,zs). You need to extract these values, and build the resulting tuple in terms of ys, zs, x1 and x2.

    (Edit) A couple of points on your revised solution:

    • You only need to deal with two elements at a time – the general case should be split x1::x2::xs
    • split [x,y] is handled by the general case – no need for another base case.
    • You’re missing the recursive call! Elements are ending up in both lists because you’re putting xs directly into both halves of your output – you need to split it first. Start with
      let (ys, zs) = split xs in ...
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new at all this c# Windows Phone programming, so this is
I am very new to this site and to programming. I started doing some
I am fairly new to programming and while doing a lot of reading this
I am totally new to math/numerical analysis programming and I was looking all over
First of all, I'm new to objective-c programming so I've probably made some mistakes
What I want: Update all new commits from server with my local repository in
I am all very new to this and am trying to use extended hex
I've been using ShowDialog() in following way for all my new Windows. SomeGui test
I'm quite new to C# and programming in general. Basically my problem is that
I have a problem programming with Android SDK 1.6. I'm doing the same things

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.