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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:24:20+00:00 2026-06-17T21:24:20+00:00

I am completely new to OCaml, so I am having some trouble with the

  • 0

I am completely new to OCaml, so I am having some trouble with the basics. For my program, I have to match a nucleotide with it’s complement (G -> C, C -> G, A -> T, T -> A) in order to find the other half of the double helix. The general idea is that DNA is composed of 2 complementary helixes, each of which is a sequence of nucleotides. Currently, I am trying to compute the other half of the double helix.

So far, I have represented the nucleotides with an enumeration and I’ve represented the DNA with a nucleotide list which corresponds to one helix.

type nucleotide = 
| G 
| C 
| A 
| T

type helix = nucleotide list

let rec complementary_helix (x:helix): helix =
| [G] -> [C]
| [C] -> [G]
| [A] -> [T]
| [T] -> [A]
end

I know something is missing here, but I don’t know how to go about it. Can somebody steer me in the right direction?

  • 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-17T21:24:22+00:00Added an answer on June 17, 2026 at 9:24 pm

    You’re basically just missing List.map:

    let complement = function
    | G -> C
    | C -> G
    | A -> T
    | T -> A
    
    let complementary_helix (x: helix) : helix =
        List.map complement x
    

    (For what it’s worth, it’s not necessary to specify types. OCaml will infer the types. It’s good style to specify them for documentation but maybe not if they’re obvious.)

    Edit

    OK, I guess this is a homework problem in which you’re supposed to use recursion to solve the problem.

    The way to think of recursion is that you want to solve a little piece of the problem, which gives you a smaller problem to solve. You pass the smaller problem to yourself (either before or after you solve your little piece). You also need to know when the problem has gotten so small there’s no more work to do on it.

    In your case, the little piece would be to translate one nucleotide to its complement. You’re doing that semi-OK (you have lists where you would really just want to work on single nucleotides). But you’re not passing the remainder of the problem to yourself to solve recursively. You’re also not checking whether the problem is so small there’s nothing to do.

    For functions on lists, around 99% of the time you’re going to make the problem smaller by splitting the list into the head (a single element) and the tail (a list that’s smaller by one). That will work for you here.

    Edit 2

    As an example of how list recursion looks, here’s a function that adds up all the integers in a list:

    let rec sum l =
        match l with
        | [] -> 0
        | head :: tail -> head + sum tail
    

    This has all the parts I described. The match is used both to tell when the problem is trivial (when the list is empty) and to split the list into the head and the tail. Assuming you had the sum for the tail (which you can get recursively), the answer is pretty obvious. You just need to add the head onto this sum. You just need to ask yourself (almost always): if I had the answer for the tail of the list, what would I need to do to combine it with the head?

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

Sidebar

Related Questions

Completely new to python i'm having problems finding this with version 2.4 I have
First off I am completely new to Javascript but I have some HTML/CSS experience.
Completely new to java and I have been playing around with regex in a
I am completely new to HTML5 and have been reading about it for the
I am completely new to Xcode and iOS developing in general. Basically I have
Completely new to Objective-C, trying to find out when I need to alloc and
I am completely new to python. I have installed it on windows. I am
I am completely new to chipmunk and I have just been using it for
I'm completely new to Core Plot and have a working bar graph, but the
I'm completely new to Linux and have been trying to get my (Windows built)

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.