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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:15:19+00:00 2026-05-21T16:15:19+00:00

I need a little utility function that generates a checksum from an array of

  • 0

I need a little utility function that generates a checksum from an array of 8 bytes.

Now, this itself is trivial, except that I can’t use byte Checksum(byte[8] input) in C# as a method declaration – I can’t specify size of array, so I have to use byte[] which can be any size, and in the method body I then need to check that input is not null and length == 8.

I’m just wondering if F# can do that? I heard that F# has a lot more options to limit acceptable parameters to a function (e.g., Discriminated Unions)?

Granted, in this trivial example F# would be overkill, but I’m curious.

  • 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-21T16:15:20+00:00Added an answer on May 21, 2026 at 4:15 pm

    Neither of the two languages can specify that a function takes an array of specific length. The problem with this is that checking whether the caller actually provides array with that length is quite difficult. It can be checked when the array is created directly by new byte[8], but all other cases require some tricky techniques.

    This is partly done by Code Contracts, which is a tool for additional checking that can be installed into Visual Studio and used with both C# and F#. It allows you to write something like:

    byte CheckSum(byte[] data) {
      Contract.Requires(data != null);
      Contract.Requires(data.Length == 8);
      // Implementation
    }
    

    Code Contracts come with a tool that gives you a warning at compile-time when you call CheckSum with a wrongly sized array. It can also generate runtime check (when it cannot statically determine that the call is correct).

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

Sidebar

Related Questions

I have a little utility that I need to use, and I'm not sure
I've got a little objective-c utility program that renders a convex hull. (This is
I would need little help here. I'm trying to get the git respository from
I need a little help getting this script doing what I want it to.
I need a little help getting a tar file to download from a website.
Need a little help here : I'm out of ideas now... Here's what I
I need to create a simple utility to make my life a little easier.
I'm new to C# (asp.net) so i need little help. On this forum I
I have a little utility I wrote in C that uses libpng. Under linux,
I'm writing a little utility that starts with selecting a file, and then I

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.