Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:59:09+00:00 2026-05-29T07:59:09+00:00

Im building a sample application where my types hierarchy isnt working with types ordering

  • 0

Im building a sample application where my types hierarchy isnt working with types ordering in Visual Studio. No matter what way i try to arrange the files ( up , down ) I cannot get all the classes be defined.

So in the order they are in f# project

type Artist() =
    let mutable artistId = 0
    let mutable name = String.Empty

    member x.ArtistId 
        with get() = artistId
        and set (value) = artistId <- value

    member x.Name
        with get() = name
        and set ( value ) = name <- value

type Genre() =
    let mutable name = String.Empty
    let mutable genreId = 0
    let mutable description = String.Empty
    let mutable albums = [new Album()]

    member x.Name 
        with get() = name
        and set (value) = name <- value

    member x.GenreId
        with get() = genreId
        and set ( value ) = genreId <- value

    member x.Description
        with get() = description
        and set ( value ) = description <- value

    member x.Albums
        with get() = albums
        and set ( value ) = albums <- value

and Album() =
    let mutable title = String.Empty
    let mutable genre = new Genre()
    let mutable albumId = 0
    let mutable genreId = 0
    let mutable artistId = 0
    let mutable price : decimal = Decimal.Zero
    let mutable albumArtUrl = String.Empty
    let mutable artist = new Artist()

    member x.Title
        with get() = title
        and set (value) = title <- value

    member x.Genre
        with get() = genre
        and set (value) = genre <- value

    member x.AlbumId
        with get() = albumId
        and set ( value ) = albumId <- value

    member x.GenreId
        with get() = genreId
        and set ( value ) = genreId <- value

    member x.ArtistId
        with get() = artistId
        and set ( value ) = artistId <- value

    member x.Price
        with get() = price
        and set ( value ) = price <- value

    member x.AlbumArtUrl
        with get() = albumArtUrl
        and set ( value ) = albumArtUrl <- value 

    member x.Artist 
        with get() = artist
        and set ( value ) = artist <- value

So in above case i get the error “Album” is not defined.

Is there a way to solve this ?. Or i just have to rethink the whole of the hierarchy structure for my types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:59:10+00:00Added an answer on May 29, 2026 at 7:59 am

    If you need to define two types that are mutually recursive (meaning that they can both refer to each other), then you need to place them in a single file and use type ... and ... syntax.

    In your example, this means that Genre and Album need to be defined like this:

    // Start a definition block using 'type' as normal
    type Genre() =  
      let mutable name = String.Empty 
      let mutable albums = [new Album()] 
    
      member x.Name  
          with get() = name 
          and set (value) = name <- value 
      member x.Albums 
          with get() = albums 
          and set ( value ) = albums <- value 
    
    // Continue single type definition block using 'and'
    and Album() = 
        let mutable genre = new Genre() 
        let mutable albumId = 0 
        let mutable artist = new Artist() 
    
        member x.Genre 
            with get() = genre 
            and set (value) = genre <- value      
        member x.AlbumId 
            with get() = albumId 
            and set ( value ) = albumId <- value      
        member x.Artist  
            with get() = artist 
            and set ( value ) = artist <- value 
    

    However, your example is using F# in a very C#-style, so the code does not really look very elegant and it may not give you many of the benefits of functional programming.

    If I wanted to represent a structure that you’re using, then I probably wouldn’t add reference to the genre into the Album type. When you place a list of albums inside a Genre, you will always be able to recover the genre when you process the data structure (i.e. to turn it into some other structure, maybe an F# record, that can be passed to data-binding). The beneift of F# is that it lets you write the domain on a few lines, but that works only for functional types.

    Using discriminated unions with a single case, you can write:

    // Type aliases to make code more readable
    type Name = string
    type AlbumID = int
    
    // Simple type definitions to represent the domain
    type Artist = Artist of Name
    type Album = Album of AlbumID * Artist
    type Genre = Genre of Name * Album list
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been building my sample asp.net application using VWD2008 and the development virtual server
I am building a paint application for android. Extending the FingerPaint application sample provided
I am building a simple application which is in charge of collecting Office files
I have a solution in Visual Studio 2010 containing 6 projects (1 web application,
I'm trying to get auto-complete working with a simple application that I'm building. Here
I am building a simple application that has a few buttons that when clicked
I'm building a simple application. It's a user interface to an online order system.
Been thinking about this for hours now. Im building a simple slideshow application, where
I'm building a simple Todo List application where I want to be able to
I am building a relatively simple Django application and apart from the main page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.