
Hey there, I'm searching for software designs in Haskell ; for example, I have a pretty good ideo of how I would arrange my modules/classes (in ocaml/(java/c++)) and how they would all fit together to create, say, a website aspirator. But I don't have any clue of the right way to do it with Haskell. I don't need a solution for this example, I'd just like to see how to manage non-trivial code. I haven't found any pointers on the interwebs. On an unrelated note, what is the simplest way to get the llvm bitcode? I understand I can compile myself ghc but it there an easier way? Thanks a lot! -- Cp

I think the general process is the same. You define your components, try to decouple them as much as possible and implement them. One thing that is different from other languages: try to write as much pure code as possible. This is great for creating composable components. There are several different ways to structure your programs. The Utrecht Haskell Compiler is structured using attribute grammars, which is (similar to) aspect-oriented programming. Another architectural pattern you see a lot is that a program is provided as a library and a very small main function. A very good example of this is XMonad. You could also look at http://www.haskell.org/haskellwiki/Haskell_in_industry, which gives some pointers to commercial projects and how they are structured. -chris On 4 aug 2010, at 13:07, Charles-Pierre Astolfi wrote:
Hey there,
I'm searching for software designs in Haskell ; for example, I have a pretty good ideo of how I would arrange my modules/classes (in ocaml/(java/c++)) and how they would all fit together to create, say, a website aspirator. But I don't have any clue of the right way to do it with Haskell.
I don't need a solution for this example, I'd just like to see how to manage non-trivial code. I haven't found any pointers on the interwebs.
On an unrelated note, what is the simplest way to get the llvm bitcode? I understand I can compile myself ghc but it there an easier way?
Thanks a lot! -- Cp _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Charles-Pierre Astolfi
I'm searching for software designs in Haskell ; for example, I have a pretty good ideo of how I would arrange my modules/classes (in ocaml/(java/c++)) and how they would all fit together to create, say, a website aspirator. But I don't have any clue of the right way to do it with Haskell.
I don't need a solution for this example, I'd just like to see how to manage non-trivial code. I haven't found any pointers on the interwebs.
This really depends on the concept you use to solve your problem. In most programming languages the glue is ready-made and tells you, how to structure your program. In Haskell you make your own glue. For example, I use monads heavily and the logical parts of my program are monad transformers. The program itself is the stack of those. Using type classes the individual transformers can communicate with each other: newtype GameT m a = GT (StateT GameConfig m a) newtype TextureT m a = TT (StateT TextureConfig m a) newtype OpenGLT m a = GLT (IdentityT m a) newtype SDLT m a = SDLT (ReaderT SDLConfig m a) type MyAppT = GameT (TextureT (OpenGLT SDLT)) game :: MyAppT IO () Another important type of glue in modern software programming is concurrency. Split your program into a number of subprograms (threads). This is very well supported in Haskell: logVar <- newEmptyMVar let logStr = putMVar logVar let logStrLn = putMVar logVar >=> const (putChar '\n') forkIO . forever $ takeMVar logVar >>= hPutStrLn stderr When using other concepts, usually by using a library, use the glue of that particular concept/library. For example, if you use Yampa to model a reactive system, your individual program parts could become signal transformers: fire :: SF Particle Particle snow :: SF Particle Particle If your current problem is a Parser, your split it into subparsers. For example to parse HTML you definitely want to parse tags and entities. To parse tags you want to parse attribute/value pairs. Use the composability features of monads to do this: tag :: Parser Tag attribute :: Parser (ByteString, ByteString) entity :: Parser Entity The possibilities are endless. You get the idea when writing actual applications. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/

Ertugrul Soeylemez
forkIO . forever $ takeMVar logVar >>= hPutStrLn stderr
hPutStrLn should become hPutStr, otherwise the output may look strange. =) Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/

This came up a month or so ago, Don Stewart and others overviewed this
topic in detail:
http://www.haskell.org/pipermail/haskell-cafe/2010-May/077154.html
On 4 August 2010 13:07, Charles-Pierre Astolfi
Hey there,
I'm searching for software designs in Haskell ; for example, I have a pretty good ideo of how I would arrange my modules/classes (in ocaml/(java/c++)) and how they would all fit together to create, say, a website aspirator. But I don't have any clue of the right way to do it with Haskell.
I don't need a solution for this example, I'd just like to see how to manage non-trivial code. I haven't found any pointers on the interwebs.
On an unrelated note, what is the simplest way to get the llvm bitcode? I understand I can compile myself ghc but it there an easier way?
Thanks a lot! -- Cp _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Charles-Pierre Astolfi
-
Chris Eidhof
-
Christopher Done
-
Ertugrul Soeylemez