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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:27:00+00:00 2026-06-05T16:27:00+00:00

let tag:String = +1 for str in readFile do let feature = str.Split [|’

  • 0
let tag:String = "+1"
for str in readFile do
    let feature = str.Split [|' '; '\t'|]
    if feature.[8] = "0" then
        tag = "-1"
    else 
        tag = "+1"

    printf "\n%s %s\n" feature.[8] tag 

The code changes tries to change the value of tag to “-1” if feature.[8] is 0, or “+1” otherwise. However the tag variable value remains “+1” throughout, irrespective of whatever the value feature.[8] is.

How does one deal with simple value changes based on conditional statement in F#?

  • 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-05T16:27:01+00:00Added an answer on June 5, 2026 at 4:27 pm

    @John Palmer has your answer, but I’ll add a bit to it…

    Note that the reason why your code compiles but does not work as you expect is because the = operator used in the context of tag = "-1" and tag = "+1" is the equality operator. So those expressions are valid but return a bool value. However, you should be receiving the following warning:

    This expression should have type ‘unit’, but has type ‘bool’. Use
    ‘ignore’ to discard the result of the expression, or ‘let’ to bind the
    result to a name.

    It would serve you well to heed that warning in your F# coding adventures.

    Also note that you can write your algorithm in a purely functional way (without mutable variables) using Seq.fold (among other alternative functional approaches):

    let tag =
        readFile 
        |> Seq.fold 
            //we use the wild card match _ here because don't need the 
            //tag state from the previous call 
            (fun _ (str:string) ->
                let feature = str.Split [|' '; '\t'|]
                //return "-1" or "+1" from the if / then expression,
                //which will become the state value in the next call
                //to this function (though we don't use it)
                if feature.[8] = "0" then
                    "-1"
                else 
                    "+1")
            ("+1") //the initial value of your "tag"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Possible Duplicate: Tokenizing in Xquery Let string a = http://ontheland.com/letus/tag/present?page=20&type=0 , need to tokenize
Let's say we have a tag called test, i.e. [code] . What I'd like
Let say I have to parse a hierarchical set of tags <tag> <subtag1 attr1=value1
Can an HTML email use an image attachment as the source for tag? Let's
I am looking for a way to generate a valid tag (string with only
I have in my .vimrc: let g:PROJECT1=/a/b/c let g:PROJECT2=/d/e/f I then do a bunch
let's say I have two xml strings: String logToSearch = <abc><number>123456789012</number></abc> String logToSearch2 =
I want to pass multiple (more than one) query string in an anchor tag.
I'm implementing a Google Suggest like autocomplete feature for tag searching using jQuery's autocomplete.

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.