F # construct for grouping constants

I have several pages with headings, and I want to be able to define these headings as string constants in some enumeration. Something like that

pageTitles =
| HOME = "Home"
| SALES = "Sales"
| MARKETING = "Marketing"
| LOGOUT = "Logout"

and then use it like:

if title = pageTitles.SALES then
   //Goto sales
+3
source share
2 answers

I think you have to put them in a module. Example:

module pageTitles =
  [<Literal>]
  let HOME = "Home"
  ...
+3
source

Combination of Daniel / Thomas recommendations:

module PageTitles =
    [<Literal>]
    let HOME = "Home" 
    [<Literal>]
    let SALES = "Sales" 
...
open PageTitles
...
match title with
| HOME -> // goto home
| SALES -> // goto sales
+4
source

Source: https://habr.com/ru/post/1789847/


All Articles