Re: [Haskell-cafe] Re: EDSL for Makefile
which looks somewhat nicer. This example also defines runTest and a test function (which calls the shell command echo to print some lines) you can try in ghci by typing runTest test... [1] http://gist.github.com/614246 Thank you very much Steffen for taking the time out for the example ... I'll study the code. -- Regards, Kashyap ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: EDSL for Makefile
The Reader monad just establishes an environment, so you can use ask to retrieve a value from the environment. Let's say you have the following types representing you Make- Environment: data MakeInfo = MakeInfo { target_ :: String , sources_ :: [String] } then inside your Monad you can access MakeInfo using ask. Because you may want to have IO available, let's use the Monad Transformer version of the Reader Monad, to define our MakeMonad: type MakeMonad = ReaderT MakeInfo IO runMake :: MakeMonad () - MakeInfo - IO () runMake m makeInfo = runReaderT m makeInfo and runMake will run it. Then you can access source and target e.g. with Applicatives: test = do sources - sources_ $ ask target - target_ $ ask system $ gcc -o ++ target ++ ++ (foldl (++) $ map (' ':) sources) Since using sources_ $ ask and such may still be annoying, this gist[1] uses some (questionable) TypeClass-hackery and some extension to overcome this problem... Using this solution one can simply write: test = sh $ gcc -o target sources which looks somewhat nicer. This example also defines runTest and a test function (which calls the shell command echo to print some lines) you can try in ghci by typing runTest test... [1] http://gist.github.com/614246 On 3 Okt., 16:56, C K Kashyap ckkash...@gmail.com wrote: On Sun, Oct 3, 2010 at 5:22 PM, steffen steffen.sier...@googlemail.com wrote: If you don't want to mention r1 explicitly, but want to refer to target, sources and such only a monadic approach (e.g. Reader Monad) might be what you want. Thanks Steffen ... would you be able to give me an example? -- Regards, Kashyap ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: EDSL for Makefile
Hi Telling from the video and the slide, Neil's make system is actually really cool. Indeed something I would really enjoy to use. Thanks :-) So you use want and need to tell the system about the static and dynamic dependencies. The want at the beginning just tells which targets to start. Since you may want to choose your task via command line, you actually would want to do something like: main = do wantDefault file1 = getArgs file1 * ... Yep, that's certainly one way of doing it (and a very natural way of doing it). Since using String everywhere for dependencies can lead to errors, it is always a good idea to replace the strings by constants you can reuse. You can also use wildcards everywhere (i.e. have a rule for *.exe), and then you only give each file once - but anyone duplicating any complex thing like a string more than once should either use a let or write a combinator on top of it - either works just fine. Shake is more kind of a library. If you want a more make-like System you can even write a preprocessor (like the haskell sinatra clone bird), which even looks for your target symbols and then generates a haskell file with target symbols replaced by Strings. It doesn't even need to generate a Haskell file, you can sequence these operations dynamically in a Monad and use Shake as a backend target for anything. Haskell is great :-) I hope the space leaks will be fixed in the future, so one can even write long running processes which automatically detect changes and rerun without user interaction and much more. Yes, although in practice you could probably already do it without issue. I think the space leak is incredibly shallow, and could be fixed in a few hours. I actually wonder about the semantic differences between want and need. Is need used to tell about dynamic dependencies and want for static dependencies? You could always do: PHONY * \_ - do need xs Instead of want xs, and have the system know about PHONY specially. want is a way of kicking off the initial set, and need is doing it after that - the real difference is the monad they run in and nothing else. The semantic idea is that want expresses that you the end user wants to have these files available, while the rules need to have files available before they continue - it's entirely possible they should be overloaded over the two monads. Thanks, Neil On 4 Okt., 05:41, C K Kashyap ckkash...@gmail.com wrote: mention_only_once file action = do want [file] file * action main = mention_only_once file1 $ \x - do need [file2] putStrLn Hello putStrLn World Thanks Bulat I guess even this should work - main = do let file1=file1 want [file1] file1 * \x - do need [file2] putStrLn Hello putStrLn World -- Regards, Kashyap ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: EDSL for Makefile
Telling from the video and the slide, Neil's make system is actually really cool. Indeed something I would really enjoy to use. It support dynamic and static dependency tracking (more or less) out of the box (by storing dependencies in a database file). So you use want and need to tell the system about the static and dynamic dependencies. The want at the beginning just tells which targets to start. Since you may want to choose your task via command line, you actually would want to do something like: main = do wantDefault file1 = getArgs file1 * ... wantDefault default [] = want [default] wantDefault _ args = want args Since using String everywhere for dependencies can lead to errors, it is always a good idea to replace the strings by constants you can reuse. Shake is more kind of a library. If you want a more make-like System you can even write a preprocessor (like the haskell sinatra clone bird), which even looks for your target symbols and then generates a haskell file with target symbols replaced by Strings. I hope the space leaks will be fixed in the future, so one can even write long running processes which automatically detect changes and rerun without user interaction and much more. I actually wonder about the semantic differences between want and need. Is need used to tell about dynamic dependencies and want for static dependencies? On 4 Okt., 05:41, C K Kashyap ckkash...@gmail.com wrote: mention_only_once file action = do want [file] file * action main = mention_only_once file1 $ \x - do need [file2] putStrLn Hello putStrLn World Thanks Bulat I guess even this should work - main = do let file1=file1 want [file1] file1 * \x - do need [file2] putStrLn Hello putStrLn World -- Regards, Kashyap ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: EDSL for Makefile
If you don't want to mention r1 explicitly, but want to refer to target, sources and such only a monadic approach (e.g. Reader Monad) might be what you want. On Oct 3, 6:14 am, C K Kashyap ckkash...@gmail.com wrote: Thanks Emil ... yeah, that works...I was wondering what I could do to not have to mention r1 explicitly. I'll check out Neil's pdf and video now - perhaps I'll find answers there. I checked out the video - nice - but I think, understandably, since its not open source yet, not much of implementations details were mentioned. So, I have this unanswered question nagging in my head. In the example below, how can I let the makefile writer refer to the target name and dependencies. Likr Emil mentioned, I could use target r1 but I want to avoid having to mention r1. http://hpaste.org/40233/haskell_makefile_edsl -- Regards, Kashyap ___ Haskell-Cafe mailing list haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: EDSL for Makefile
On Sun, Oct 3, 2010 at 5:22 PM, steffen steffen.sier...@googlemail.com wrote: If you don't want to mention r1 explicitly, but want to refer to target, sources and such only a monadic approach (e.g. Reader Monad) might be what you want. Thanks Steffen ... would you be able to give me an example? -- Regards, Kashyap ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe