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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:49:59+00:00 2026-06-01T00:49:59+00:00

I am working on a project with OCaml and there are some problems regarding

  • 0

I am working on a project with OCaml and there are some problems regarding to arrays that I am not sure with. I am not allowed to use the List module, so please give me some idea or suggestion with my works.

First, I already implemented a function 'a list -> 'a list called uniq that return a list of the uniq elements in an array, for example uniq [5;6;5;4] => [6;5;4]

Here is my implementation:

let rec uniq x =
let rec uniq_help l n = 
    match l with
        [] -> []
    |   h :: t -> uniq_help t, n if (n = h) else (h :: (uniq_help(t, n)))
match x with
    [] -> []
|   h::t -> uniq_help t, h
;;

I mot sure this is a correct implementation, can someone give me some suggestion or correctness?

  • 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-01T00:50:00+00:00Added an answer on June 1, 2026 at 12:50 am

    You functions are syntactically incorrect for various reasons:

    • uniq_help takes two elements so you have to invoke it using uniq_help t n, not uniq_help(t, n) and the like.
    • an if/else expression should have the form of if cond then expr1 else expr2.
    • to use uniq_help locally in uniq, you need an in keyword.

    After fixing syntax errors, your function looks like:

    let rec uniq x =
      let rec uniq_help l n = 
        match l with
        | [] -> []
        | h :: t -> if n = h then uniq_help t n else h::(uniq_help t n) in
      match x with
      | [] -> []
      | h::t -> uniq_help t h
    

    However, to be sure that each element is unique in the list, you have to check uniqueness for all of its elements. One quick fix could be:

    let rec uniq x =
         (* uniq_help is the same as above *)
         match x with
         | [] -> []
         | h::t -> h::(uniq_help (uniq t) h)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working a project that does not have a trunk / branches /
I'm working on project that lets users choose some scientific authors and columnists and
I want to make sure that the project is configured entirely for C (NOT
I'm currently working on a small project with OCaml; a simple mathematical expression simplifier.
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am working a project with many NUnit tests, that were already written long
When working with Project Euler problems I often need large (> 10**7) bit array's.
I'm currently editing a working project with some experience on PHP. I know a
I'm copying some objective c++ files over from another (working) project. I get no
I'm working on project that uses a tab bar at the bottom to flip

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.