PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 28, 2022

[FIXED] How to check in f# if the set is Empty?

 October 28, 2022     f#, is-empty     No comments   

Issue

How can I check if the set is empty, I have implemented the following code if the set has an empty set then I should get the value true else false, for example: [1; 2; []] this set should result in true and if the set is [1; 2; 3] this should result in false because this one does not have an empty set in it. Following is the code that gives me an error:

let rec isEmpty S =
   match S with
  |[] -> true
  |_ -> false
  |e::rest -> ([]=e) || (isEmpty [] rest)

Solution

Unfortunately for your use case F# is quite a bit more 'strongly typed' than you would like here.

In F# a value like [1; 2; 3] is an int list, and an int list won't accept a value like [1; 2; []].

Maybe you could try to define a new (recursive) datatype for your problem.



Answered By - Robert Nielsen
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing