Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone point me to examples of multiparadigm (object-functional) programming in F#?

Can someone point me to examples of multiparadigm (object-functional) programming in F#?

I am specifically looking for examples which combine OO & functional programming. There's been a lot of talk about how F# is a hybrid language but I've not been able to find examples which demonstrate the example of multiparadigm programming.

Thanks

like image 602
SharePoint Newbie Avatar asked Nov 06 '10 18:11

SharePoint Newbie


1 Answers

I made a small (600 lines) Tetris clone with F# that is Object Oriented using XNA. The code is old (uses #light) and isn't the prettiest code you will ever see but it's defiantly a mix of OOP and functional. It consists of ten classes. I don't think I pass any first class functions around but it's a good example of the F#'s functional power in programming the small.

  • MyGame - Inherits XNA main game class and is the programs entry point.
  • Board - Keeps track of pieces that are no longer moving and horizontal line completes.
  • UI - The UI only has two states (playing and main menu) handled by bool stateMenu
  • Tetris - Handles game state. Game over and piece collision.
  • Piece - Defines the different Tetris shapes and their movement and drawing.
  • Player - Handles user input.
  • Shape - The base graphic object that maps to primative.
  • Primative - Wraps the Vertex primitive type.

I made a rough class diagram to help. If you have any questions about it feel free to ask in the comment section.

alt text

like image 162
gradbot Avatar answered Oct 13 '22 22:10

gradbot