Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Interfaces might be a closer fit to what you have described in the updated question:</p> <pre><code>type Small = abstract v1 : int type Large = inherit Small abstract v2 : int let fn (value: Small) = printfn "%d" value.v1 let large = { new Large with member small.v1 = 5 member large.v2 = 6 } fn large </code></pre> <p>With interfaces the <code>Large</code> type can now be composed from 1 or more <code>Small</code> types. Functions can expect only the <code>Small</code> type they need, and the caller can simply pass a <code>Large</code> type to each function.</p> <p>Depending on the scenario you might also consider having a <code>Large</code> record type that implements one or more <code>Small</code> interfaces.</p> <pre><code>type Small = abstract v1 : int type Large = { v1: int; v2: int } with interface Small with member this.v1 = this.v1 let fn (value: Small) = printfn "%d" value.v1 let large = { v1 = 5; v2 = 6 } fn large </code></pre> <p>Yet another option is to define a union for all the possible <code>Small</code> items, and define <code>Large</code> as a list:</p> <pre><code>type Item = | V1 of int | V2 of int type Large = Item list let (|Small|) (large:Large) = large |&gt; List.pick (function V1(v1) -&gt; Some(v1) | _ -&gt; None) let fn (Small value) = printfn "%d" value let large = [V1(5);V2(6)] fn large </code></pre> <p><a href="http://msdn.microsoft.com/en-gb/library/dd233248.aspx" rel="nofollow">Active patterns</a> can be used to extract <code>Small</code> types from the data. An example of this kind of scheme is the <a href="http://www.fixprotocol.org/" rel="nofollow">FIX protocol</a> which composes large financial data blocks from small tagged data blocks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload