Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does f# decide which file to run on startup?

Tags:

f#

Be nice, I'm a total newbie to F#. I have created my first console app, and I can't figure out how F# decides which of my .fs files its going to run on startup. Normally apps have an entry point, and the F# forms projects I've seen have an entry point. My console project does not.

It always seems to start with the last file I've added, which is a giant pain. I can't believe its supposed to work this way. I must be doing something wrong.

like image 561
Jonathan Beerhalter Avatar asked Mar 19 '09 20:03

Jonathan Beerhalter


2 Answers

F# does support entry points, with EntryPointAttribute. See the last screenshot of this blog for details. The 'main' function takes a string array and returns an int, and the EntryPoint must be in the last code file in the project. See also 12.1.4 of the language spec.

Note that if you do not provide an explicit entry point, then the 'top level code' in the last file of the project effectively behaves like 'main'.

(Incidentally, see also this blog for info on managing ordering files in a project inside VS.)

like image 132
Brian Avatar answered Nov 16 '22 01:11

Brian


EDIT Read Brian's answer for latest information

My answer is linking to out-dated information.

At this point F# does not support an explicit entry point for an application. It has an implicit entry point which is, as you observed, the last file in the project.

This thread has more details: http://cs.hubfs.net/forums/thread/4151.aspx

like image 45
JaredPar Avatar answered Nov 16 '22 02:11

JaredPar