Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have cabal init create Main.hs #2304

Closed
cdepillabout opened this issue Dec 26, 2014 · 15 comments
Closed

have cabal init create Main.hs #2304

cdepillabout opened this issue Dec 26, 2014 · 15 comments

Comments

@cdepillabout
Copy link
Contributor

I often use cabal init when creating a new package, often before I've even started writing any code. Using cabal-install version 1.20.0.4, it doesn't seem like cabal init will create Main.hs for you, even if it doesn't already exist.

It would be nice cabal init created a short Main.hs for you, if it doesn't already exist.

Ideally, I'd like to be able to have the following workflow:

# make a new directory for my project
$ mkdir my-project && cd my-project

# initialize my sandbox
$ cabal sandbox init
...

# create the .cabal file
$ cabal init
...

# cabal init would have created a Main.hs like below
$ cat Main.hs
module Main where

main = putStrLn "Hello World!"

# now, you can immediately run `cabal install`
$ cabal install
...

# this produces an executable that you can immediately run
$ ./.cabal-sandbox/bin/my-project
Hello World!
$

If I were to send a pull request for this, would there be any interest in it?

@23Skidoo
Copy link
Member

/cc @byorgey

@cdepillabout
Copy link
Contributor Author

This feature would of course need to work well with #1989.

@fujimura
Copy link
Contributor

fujimura commented Jan 1, 2015

In my understanding, cabal init is a command to cabalise the exisiting project. So, generating files are a bit different from original purpose.

Aside from original purpose, I think if cabal init generates sufficient files to start new project, it'd be helpful for many developers.

@byorgey
Copy link
Member

byorgey commented Mar 5, 2015

Yes, I don't think this really fits with the purpose of cabal init. @cdepillabout , perhaps you would be interested in a project like https://github.com/fujimura/hi which seems to be more what you are looking for.

@byorgey byorgey closed this as completed Mar 5, 2015
@cdepillabout
Copy link
Contributor Author

@byorgey, you're right. hi is really nice and it could definitely be used for what I want, but it's a little "heavy" for just generating a Main.hs file.

I realize that cabal init was originally used for cabalizing an existing Haskell project, but I almost always end up using it before I actually write any Haskell code. For my specific use case, it would be nice if it created a Main.hs for me.

Maybe I should seriously look into using hi to generate projects instead of cabal init.

@byorgey
Copy link
Member

byorgey commented Mar 10, 2015

@cdepillabout , if hi is too heavyweight, you could just write a little script that calls cabal init and then copies a fresh Main.hs into the directory.

@cdepillabout
Copy link
Contributor Author

That's true, I'll look into doing that.

@cgag
Copy link
Contributor

cgag commented Mar 13, 2015

Is the purpose really to cabalize existing non-cabal projects? I might be wrong but I feel starting new projects with "cabal init" has to be a way more common use-case. Creating a working project from "cabal init" seems like a very nice thing to have, especially for beginners.

@23Skidoo
Copy link
Member

Perhaps init should have two modes of operation. When run in an empty directory, init could default to the "new project" mode, and in a non-empty one to "cabalize" mode.

@erikd
Copy link
Member

erikd commented Mar 13, 2015

I think @23Skidoo's ideas of two modes is a good. Personally, "cabalize" an existing project is by far my most common use case.

@bitemyapp
Copy link
Contributor

Two modes...could be okay. I'm a little iffy on it. The overloading of commands is already getting to be a bit much.

I'm the opposite of @erikd - cabal init is usually my first command. It's possible that an official templating function could help here. Some exist already but aren't widely known.

@cdepillabout
Copy link
Contributor Author

@bitemyapp, I'm the same as you.

As for a templating function, have you tried hi mentioned above? It is what you're looking for?

What I'd like more than a templating function is just something that creates Main.hs so I can run cabal run (or cabal install) right away. For my personal use-case it doesn't have to be a templating function.

@cgag
Copy link
Contributor

cgag commented Mar 13, 2015

I'm not actually sure why it would need two different modes. While I think cabal init is probably most common use-case, this seems like an improvement for both uses. When "cabalizing" a project, I imagine you'd already have a main that already exists, so this wouldn't affect things. If you didn't, I imagine you'd need to create one as well.

Re: hi templating, I'd like it if cabal just did templating. I know lein (Clojure) does it, and I believe it's being considered by Cargo (rust) as well.

@byorgey
Copy link
Member

byorgey commented Mar 14, 2015

Well, perhaps you are all right, having cabal init just create a simple Main.hs if one does not already exist would be useful. I will reopen this issue; pull requests welcome.

@cdepillabout
Copy link
Contributor Author

This has been implemented and merged in #2483. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants