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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:20:41+00:00 2026-05-28T17:20:41+00:00

Here is a snippet of code from my book, and I’m not sure about

  • 0

Here is a snippet of code from my book, and I’m not sure about how the matching works apparently because it seems the first case matches everything. Here are the warnings Ocaml throws at me:

# let zero = 0;;
# let one = 1;;
# let rec fib i =
match i with
zero -> zero
| one -> one
| j -> fib (j - 2) + fib (j - 1);;
Characters 57-60:


Warning: this match case is unused.
Characters 74-75:
Warning: this match case is unused.
| one -> one
^^^
| j -> fib (j - 2) + fib (j - 1);; 
^
val fib : int -> int = <fun>
# fib 1;;
- : int = 1
# fib 2002;;
- : int = 2002
  • 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-28T17:20:42+00:00Added an answer on May 28, 2026 at 5:20 pm

    This is a fairly common source of confusion. In essence you want to think of patterns as being built from constants (like 0 and 1) and identifiers that are bound by the pattern.

    When an identifier shows up in a pattern, it matches anything at all, and binds the matched value to the identifier. An identifier in a pattern does not refer to any previous value associated with the identifier. So, indeed, your pattern will always match the first case and bind zero to the value of i.

    You could imagine that you’d like to be able to give names to constant values, then use the names rather than the constants in a pattern. However OCaml (like other FP languages) doesn’t work that way. One advantage (seems to me) is that it keeps things simple.

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

Sidebar

Related Questions

The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
Here's a snippet of code from an sqlite database application I'm working on: my
Here is a snippet of my code from my ability class if user.admin? can
Here's a snippet of code from within TurboGears 1.0.6: [dispatch.generic(MultiorderGenericFunction)] def run_with_transaction(func, *args, **kw):
Here's a snippet of code from a shell script I have written: for src
Here is a snippet of code from django.core.exceptions : class MiddlewareNotUsed(Exception): This middleware is
Here is a little snippet of code from Wikipedia's article on malloc(): int *ptr;
I have a code snippet from here : volatile int volatileInt; int usualInt; void
Here's a snippet of code I saw on the web and I'm wondering if
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'

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.