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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:06:20+00:00 2026-06-09T11:06:20+00:00

Hello I have written the following code. My objective was to write a function

  • 0

Hello I have written the following code.

My objective was to write a function called getWoeid which will check if the command line parameter is an array with 1 element, and that element is an integer.

My code works… but I am calling the TryParse method two times… I wonder if there is a way in which I can call this only once.

Also, can you confirm if this way of using pattern matching for validating command line parameters is correct?

open System;
open System.Xml;

let getWoeid args =   
  let retVal = 0
  match args with      
  | [|a|] when fst (Int32.TryParse(a)) = true -> 
      printfn "%s" "Starting the processing for woeid "
      Some(snd (Int32.TryParse(a)))      
  | _ -> failwith "Usage XmlRead WOEID"       

[<EntryPoint>]
let main args = 
  let woeid= 
    try   
      getWoeid args          
    with
      | Failure (msg) -> printfn "%s" msg; None

  0
  • 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-09T11:06:22+00:00Added an answer on June 9, 2026 at 11:06 am

    You can define active pattern:

    let (|Int|_|) s = 
        match System.Int32.TryParse s with
        | true, v -> Some v
        | _ -> None
    
    let getWoeid args = 
        match args with
        | [|Int v|] -> Some v
        | _ -> None
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following code which works fine MsgBox(AddSomething(Of String)(Hello, World)) Public Function AddSomething(Of
i have written the following code to copy a string hello world to another
Hello there i have written some code in jquery to add new input type
I have written a command-line tool that uses sub-commands much like Mercurial, Git, Subversion
hello i have following code and it works fine for finding and replacing string...
I have written a clean app (Hello, World) which builds correctly using Debug|Simulator and
I have written the following C99 code and was wondering about the struct declaration.
I have written a script in haskell named testscript with the following code: #!/usr/bin/env
I have written the following code #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/filesystem.hpp>
I have written a small program just like hello the world , everything was

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.