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

Comments

Projects
None yet
8 participants
@cdepillabout
Contributor

cdepillabout commented Dec 26, 2014

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

This comment has been minimized.

Member

23Skidoo commented Dec 26, 2014

/cc @byorgey

@cdepillabout

This comment has been minimized.

Contributor

cdepillabout commented Dec 27, 2014

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

@fujimura

This comment has been minimized.

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

This comment has been minimized.

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 Mar 5, 2015

@cdepillabout

This comment has been minimized.

Contributor

cdepillabout commented Mar 9, 2015

@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

This comment has been minimized.

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

This comment has been minimized.

Contributor

cdepillabout commented Mar 10, 2015

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

@cgag

This comment has been minimized.

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

This comment has been minimized.

Member

23Skidoo commented Mar 13, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

bitemyapp commented Mar 13, 2015

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

This comment has been minimized.

Contributor

cdepillabout commented Mar 13, 2015

@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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

cdepillabout commented May 3, 2015

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