F# Training
F# Training
F# Training
  • Presentation
  • Fundamentals
    • Introduction
    • Syntax
      • Bases
      • Functions
      • Rules
      • Exceptions
    • First concepts
    • πŸ”Quiz
  • Functions
    • Signature
    • Concepts
    • Syntax
    • Standard functions
    • Operators
    • Addendum
    • πŸ”Quiz
    • πŸ“œSummary
  • Types
    • Overview
    • Tuples
    • Records
    • Unions
    • Enums
    • Anonymous records
    • Value types
    • πŸ“œRecap
    • Addendum
  • Monadic types
    • Intro
    • Option type
    • Result type
    • Smart constructor
    • πŸš€Computation expression (CE)
    • πŸš€CE theoretical basements
    • πŸ“œRecap
  • Pattern matching
    • Patterns
    • Match expression
    • Active patterns
    • πŸš€Fold function
    • πŸ“œRecap
    • πŸ•ΉοΈExercises
  • Collections
    • Overview
    • Types
    • Common functions
    • Dedicated functions
    • πŸ”Quiz
    • πŸ“œRecap
  • Asynchronous programming
    • Asynchronous workflow
    • Interop with .NET TPL
    • πŸ“œRecap
  • Module and Namespace
    • Overview
    • Namespace
    • Module
    • πŸ”Quiz
    • πŸ“œRecap
  • Object-oriented
    • Introduction
    • Members
    • Type extensions
    • Class, Struct
    • Interface
    • Object expression
    • Recommendations
Powered by GitBook
On this page
  • πŸ•ΉοΈ Quiz wrap up
  • Conclusion

Was this helpful?

Edit on GitHub
  1. Types

Recap

πŸ•ΉοΈ Quiz wrap up

// Match types with concepts (1 to many)
type Color1 = int * int * int
type Color2 = Red | Green | Blue
type Color3 = Red=1 | Green=2 | Blue=3
type Color4 = { Red: int; Green: int; Blue: int }
type Color5 = {| Red: int; Green: int; Blue: int |}
type Color6 = Color of Red: int * Green: int * Blue: int
type Color7 =
    | RGB of {| Red: int; Green: int; Blue: int |}
    | HSL of {| Hue: int; Saturation: int; Lightness: int |}

// A. Alias
// B. Enum
// C. Record
// D. Record anonyme
// E. Single-case union
// F. Union
// G. Union enum-like
// H. Tuple
Answer
Types
Concepts

type Color1 = int * int * int

H. Tuple + A. Alias

type Color2 = Red ∣ Green ∣ Blue

G. Union enum-like

type Color3 = Red=1 ∣ Green=2 ∣ Blue=3

B. Enum

type Color4 = { Red: int; Green: int… }

C. Record

type Color5 = {∣ Red: int; Green: int… ∣}

D. Anonymous Record + A. Alias

type Color6 = Color of Red: int * …

E. Single-case union + H. Tuple

type Color7 = RGB of {βˆ£β€¦βˆ£} ∣ HSL of {βˆ£β€¦βˆ£}

F. Union + D. Anonymous Record

Conclusion

Lots of ways to model!

πŸ’‘ Opportunity for:

  • Team discussions

  • Business domain encoding in types

PreviousValue typesNextAddendum

Last updated 1 month ago

Was this helpful?

πŸ“œ