News aggregator

Does anyone have experience building a Windows DLL from Haskell code and then calling it from C++ code? I’m having a tough time just getting the DLL built. I opened this Stack Overflow question to ask about the specific problem I’m having right now, but I’d appreciate any advice people can offer.

(It seems like calling C code from Haskell is by far the more common use of the FFI. Information on building a DLL is hard to find and a lot of what I’ve seen is contradictory—if I ever figure this out I’ll write a detailed blog post with instructions and pointers.)

FLOPS 2016: 13th International Symposium on Functional and Logic Programming
March 3-6, 2016, Kochi, Japan
Call For Papers http://www.info.kochi-tech.ac.jp/FLOPS2016/
New: best paper award; in-cooperation with ACM SIGPLAN
Writing down detailed computational steps is not the only way of
programming. The alternative, being used increasingly in practice, is
to start by writing down the desired properties of the result. The
computational steps are then (semi-)automatically derived from these
higher-level specifications. Examples of this declarative style
include functional and logic programming, program transformation and
re-writing, and extracting programs from proofs of their correctness.
FLOPS aims to bring together practitioners, researchers and
implementors of the declarative programming, to discuss mutually
interesting results and common problems: theoretical advances, their
implementations in language systems and tools, and applications of
these systems in practice. The scope includes all

It still confuses me that Either never had an accompanying EitherT in transformers, like MaybeT for Maybe. What is the reason for Either to be excluded?

(I know about Control.Monad.Except etc but those are besides the point)

As it is now, to get an EitherT one must import a separate library EitherT but that has been deprecated in favor of either which has a lot of dependencies from outside of base and transformers. I don't doubt those are all good, but it is kind of overkill to pull all of them just to get an either transformer.

Even more strange is that either has mtl as a dependency, while mtl is another set of transformers that lives under a different namespace (Control.Monad rather than Control.Monad.Trans).

(I also just realized that there is no Control.Monad.MaybeT in mtl, so one has to import MaybeT to get that one.)

I'm asking this because there are some handy read/show functions for RGB colors, but there is no safe way to read strings with them. If anyone knows of a library that provides this, that would be great.

Hello,
I have been looking at Hackage for a package/library that
supports Haskell interoperability with Java/Scala. Didn't see any such
support. If true, is there any project in the works?
Thanks,
Vasili

which is where I'm trying to get but I don't know any property that would let me do that which makes me ask: Am I doing some step wrong? Or simply those patterns aren't equivalent and the whole thing is pointless?

I'm totally new to Haskell, though I've worked with ML and Racket in the past. I wanted to impart upon the wisdom of /r/haskell, and see what recommended tools, editors, and development environments exist for this language.

I'm currently using gVim or Notepad++ on Windows, but would be interested in switching to Linux if it offers a better developer experience.

I've also tried using SublimeText3 on Windows, but have had some integration issues when installing packages with cabal that ST3 needs.

There was an online discussion about iteration times in Haskell and whether and why they are slow. For me, it’s not slow. I do all my Haskell development using a REPL. Here are some tips I wrote up in that discussion.

Prepare for GHCi use

The first thing you want to do before writing anything for your project is make sure you can load your code in the REPL; GHCi. Sometimes you have special configuration options or whatnot (cabal repl and stack ghci make this much easier than in the past). The sooner you start the better. It can be a PITA to load some projects that expect to just be a “start, run and die” process, they often launch threads without any clean-up procedure; in this way the REPL makes you think about cleaner architecture.

Make sure it scales

Learn how to make GHCi fast for your project so that you don’t hit a wall as your project scales. Loading code with byte-code is much faster than object code, but loading with object code has a cache so that in a 100 module project if you only need to reload one, it’ll just load one. Make sure this is happening for you, when you need it. Dabble with the settings.

Write small, parametrized functions

Code that is good for unit tests is code that is good for the REPL. Write small functions that take state as arguments (dependency injection) rather than loading their own state, then they can be ran in the REPL and used in a test suite easily. Regard functions that you can’t just call directly with suspicion.

Test work-in-progress implementations in the REPL

While writing, test your function in the REPL with typical arguments it will expect, rather than implementing a function and then immediately using it in the place you want to ultimately use it. You can skip this for trivial “glue” functions, but it’s helpful for non-trivial functions.

Setup/teardown helpers

Write helpful setup/teardown code for your tests and REPL code. For example, if you have a function that needs a database and application configuration to do anything, write a function that automatically and conveniently gets you a basic development config and database connection for running some action.

Make data inspectable

Make sure to include Show instances for your data types, so that you can inspect them in the REPL. Treat Show as your development instance, it’s for you, don’t use it for “real” serialization or for “user-friendly” messages. Develop a distaste for data structures that are hard to inspect.

Figure out the fastest iteration for you

Use techniques like :reload to help you out. For example, if I’m working on hindent, then I will test a style with HIndent.test chrisDone "x = 1", for example, in the REPL, and I’ll see the output pretty printed as Haskell in my Emacs REPL. But I work on module HIndent.Style.ChrisDone. So I first :load HIndent and then for future work I use :reload to reload my .ChrisDone changes and give me the HIndent environment again.

Configuration

Make sure you know about the .ghci file which you can put in your ~/ and also in the project directory where GHCi is run from. You can use :set to set regular GHC options including packages (-package foo) and extensions (-XFoo), and any special include directories (-ifoo).

More advanced tricks

Consider tricks like live reloading; if you can support it. I wrote an IRC server and I can run it in the REPL, reload the code, and update the handler function without losing any state. If you use foreign-store you can make things available, like the program’s state, in an IORef or MVar.

This trick is a trick, so don’t use it in production. But it’s about as close as we can get to Lisp-style image development.

In summary

Haskell’s lucky to have a small REPL culture, but you have to work with a Lisp or Smalltalk to really know what’s possible when you fully “buy in”. Many Haskellers come from C++ and “stop program, edit file, re-run compiler, re-run whole program” cycles and don’t have much awareness or interest in it. If you are such a person, the above probably won’t come naturally, but try it out.

Stumbled upon the spoon package. I wanted to see if I could make it work for functions instead of just values. After fiddling around with functional dependencies I've managed to get something that works! The code is very short so I'll post the whole thing.

The result is the magical save function that you can apply to any other function (of arbitrary arity) and it will wrap the END result of that function into a Maybe. Just when everything goes well, Nothing when there's an exception.

I'm not sure if there's any practical use case where this is advantageous over just spooning the return value but I guess it's at least more compact. As you can see it's about as offensive to safety as is gets. All it's lacking is TH :D

I've commented out the type signature of safeDiv to show that the type is successfully inferred.