strangelights.com

Main F# Site

Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Search
List all versions List all versions
Formatting Tips For Code With Actions
.

Check out the formatting tips on the right for help formatting and making links.

Use the template below:

Summary

People frequently want to write code that contains embedded actions (also called statements, i.e. the code is imperative - in F# these are just expressions that return the type "unit", which is here essentially equivalent to the type "void"). Here are some guidelines for which constructs to use to write that code.

   <statement>;
   <statement>;
   <statement>

("<statement>" is an expression with type "unit" - i.e. "void").

   let f x = 
     <statement>;
     let y = <expression> in 
     let z = <expression> in 
     <statement>;
     <expr>

In terms of cost each "let" binding is just like declaring a local in C# with some initialization code. That is, multiple "let/in" pairs are not expensive, and nor is nesting them.

   if x then (
     <statement>;
     <statement>
   ) else (
     <statement>;
     <statement>
   )


   if x then begin 
     <statement>;
     <statement>
   end else begin
     <statement>;
     <statement>
   end
  begin match x with 
  | A -> 
     <statement>;
  | B -> 
     <statement>;
  end;
  <statement>
   let _ = <statement> in 
   let _ = <statement> in
   type C = 
     class
       val id: string
       new(id) = 
            { id = id }
          then 
            printf "the object has been initialized\n"
   do <statement> 
   let _ = <statement>
   let x = 1;;
   x+x;;
Welcome to F Sharp Wiki, view the HomePage

This site supports the new NoFollow anti-spam initiative.

Recent Topics

Copyright 2005, Robert Pickering (Others where credited) | Terms of Use