News aggregator

Console Watch - call clock_nanosleep via FFI

Haskell on Reddit - Sat, 02/21/2015 - 12:17pm

I am learning Haskell by writing simple programs. I have implemented simple console watch in Haskell that uses FFI to do system call clock_nanosleep. It prints current local time once a second. Use Ctrl-C to stop it.

$ ./watch

Sat Feb 21 12:45:04 2015

Sat Feb 21 12:45:05 2015

C

This is text of program in Haskell Console Watch in Haskell

and this is text of C prototype Console Watch 2 in C

The program is self contained and should be compilable under plain ghc. The fragments of posix-timer were copied for call of clock_nanosleep and clock_gettime .

I would like to hear any comments on the program.

Is it ok to use recursive call to emulate "for loops"?

The strace logs for C version is different from Haskell version. Each 10 ms Haskell generates SIGVTALRM that interrupts clock_nanosleep. I have tried to disable interrupts during call of clock_nanosleep - but in that case program reacts with delay on press of Ctrl-C. Can it be mitigated?

EDIT: Put call to clock_nanosleep in C version in while cycle. Previous version Console Watch in C

submitted by scrambledeggs71
[link] [2 comments]
Categories: Incoming News

Haskell and Cosmology

Haskell on Reddit - Sat, 02/21/2015 - 10:26am
Categories: Incoming News

how can I do this the best

haskell-cafe - Sat, 02/21/2015 - 10:03am
Hello, Im busy with a programm which translates log files to another format. I also have to look if the lines in the old one have the rigtht format. Schould I check the format and also if another field contains a I, E or W. Or schould I do the checking in one clause and make another case on the rest ? Roelof
Categories: Offsite Discussion

Can there be sum type polymorphism, like there can be row polymorphism?

Haskell on Reddit - Sat, 02/21/2015 - 9:13am

Hi. Recently I've found that there's a lot of talk about records in Haskell, and how other languages handle records. One of the issues I found is "row polymorphism", where some other languages allow functions to be applied to more than a single type of record, like so:

f :: {a: Int, b: Int | p} -> Int f x = x.a + x.b g :: {a: Int, b: Int, c: Int} -> Int g x = f x

Defining the function "g" would not give you a type error, because "f" is polymorphic over the type of the record (here the polymorphism is specified in the type with "p").

But I haven't seen any talks about sum types, and if you could have something similar with them or not. For instance, could there be a language (or language extension in the case of Haskell) that can allow you to do this?:

f :: Int -> [x: Bool | y: Bool | p] f 0 = x True f 1 = x False f n = y True g :: Int -> [x: Bool | y: Bool | z: Bool] g n = f n

If you see records as "labelled product types", and are able to define row polymorphism (and/or extensible records, etc) on them, then shouldn't you also be able to define "labelled sum types" and define polymorphism over them too? Considering they are dual, you should be able to define both at the same time, right?

I can see polymorphic sum types being useful in things like error handling for instance (where you have functions that give you different possible errors as a sum type, but you can extend those errors outside of that function application if you want).

Note: The syntax above is there to make it easier to show what I mean. I know it's not valid Haskell

submitted by gonzaw308
[link] [22 comments]
Categories: Incoming News

Looking for: hscolour with go-to-definition clickable code

Haskell on Reddit - Sat, 02/21/2015 - 7:06am

In a discussion on Reddit, probably a year ago or so, somebody linked in a comment a tool they had built that was like hscolour, but you could click on the identifiers to go-to-definition.

Similar to this (http://goto.ucsd.edu/~rjhala/Annot/hscolour/src/Language-Haskell-HsColour-CSS.html#) but with go-to-definition instead of showing the types on hover.

I've searched for the last two hours, but I cannot find it at all.

Does anybody remember what the name of the tool, the link to the demo page that was posted, or anything related, was?

Pointers would be much appreciated!

submitted by nh2_
[link] [6 comments]
Categories: Incoming News

Is there a better way to think about typeclasses?

Haskell on Reddit - Sat, 02/21/2015 - 6:28am

This is about typeclasses in general but I'll use Functor as an example.

Recently I was reading something about profunctors and there was an expression like this one

f a -> b -> f (a, b)

The question was, can you write that function for any functor (or something similar; I may be butchering the concepts here) and I realized I had no intuition about functors in general.

Sure, I can imagine that there's [] or Maybe instead of f. For those I'm sure that I could write the given function, but there's no machinery in my brain that would make me confident I can make a claim about every one of them.

Of course, this specific example is simple and the answer is yes.

g fa b = fmap (\a -> (a, b)) fa

But the one with

f (Either a b) -> Either (f a) b

turned out not to be possible. Now, what I'm asking is: Is there a unified way to think about EVERY functor? And I don't mean just following the definition. I'm talking about intuition. The same goes, and perhaps even more so, for monads. When I see a function that operates on Monad m, I really can't say I know what it does. I can answer questions like "What does it do for lists?" or "What does it do for IO?", but I can't answer "What does it do for m?".

Sometimes I can decompose the function into smaller ones that work on monads. In those cases I can say "traverse maps the monadic function over the functor and then sequences it" but again, the only intuition I get from it is by substituting the functor and the monad for some specific ones.

submitted by Darwin226
[link] [12 comments]
Categories: Incoming News

FLTK GUI Bindings - Alpha Release

haskell-cafe - Sat, 02/21/2015 - 4:32am
I'm pleased to announce the alpha release of Haskell bindings [1] to the FLTK [2] GUI library. On Linux and Mac this package and FLTK 1.3.3 [3] should install pretty smoothly. The library covers about 80+% of API and has 60+ widgets that can be used transparently from Haskell. You can read more about the motivation behind the library, installation instructions and quick start documentation here [4]. The package also comes with 14 demos to show you how to get started. There still isn't any support for Windows because I don't have access to a Windows machine, and don't have any experience with the Windows C/C++ build tools. The code itself should be fully portable. I could use some help here. Please report any issues on the Github page [5]. Hope you enjoy and I'd love any feedback on the install and development process. Thanks! -deech [1] http://hackage.haskell.org/package/fltkhs-0.1.0.0 [2] http://fltk.org [3] http://www.fltk.org/software.php?VERSION=1.3.3&FILE=fltk/1.3.3/fltk-1.3.3-source.tar.gz [4]
Categories: Offsite Discussion

Where to go after LYAH?

Haskell on Reddit - Sat, 02/21/2015 - 3:26am

I'm almost done with LYAH, and I'm wondering where to go from here? I'd like to start working on some personal poject to build on my understanding of functional programming, but I have no idea where to start and/or what to do.

Is there any guide that basically walks you through on how to develop a simple project in Haskell? The project should be an utility program or game, something concrete.

submitted by The_Kilo
[link] [14 comments]
Categories: Incoming News

Trouble with forkProcess

haskell-cafe - Sat, 02/21/2015 - 2:58am
Hi folks, I’d love to get a sense of the prevailing wisdom with respect to forkProcess from System.Posix.Process. I’m building a multithreaded (STM) application with potentially many threads simultaneously reading and writing to pieces of (an otherwise rather large) shared state. Occasionally I would like to record a whole snapshot of that state, and it seems to me a natural way to accomplish this is to fork a process (eliminating all the other threads) and perform a read-only dump of the state. This dump can be time-consuming, which is why I’d rather not have contention with other threads that may be trying to modify the state while I’m dumping. My experience with forkProcess so far is that sometimes it works brilliantly, and other times it just deadlocks. I’m at a loss to understand what the problem is, but the deadlock seems to occur before the new process gets any control -- certainly before it has started to access any of the shared state. I’m aware of the giant warning in the forkProces
Categories: Offsite Discussion

openBinaryTempFile

libraries list - Sat, 02/21/2015 - 2:03am
We are using this function from base in Darcs in a way that causes trouble: the returned file handle is closed immediately and only the filename is passed on. Then the file gets re-opened and closed again and some time later deleted. If openBinaryTempFile is used in this way a few times in a row, it returns the same file name every time. I tested this with a small test program. My question: is openBinaryTempFile supposed to behave like that (if used in this way)? I am testing this on an ubuntu trusty with ghc-7.6.3, meaning base-4.6.0.1. Has the function been changed in later versions? Cheers Ben
Categories: Offsite Discussion

Is there any simple explanation (or, better, implementation) of type inference for the simply typed lambda calculus in Haskell?

Haskell on Reddit - Fri, 02/20/2015 - 9:36pm

I've been looking though Google for quite some time but couldn't find anything convincing, other than huge papers, and an 8-liner implementation on Curry, which used builtin unification. Anything simpler would be highly appreciated.

submitted by SrPeixinho
[link] [4 comments]
Categories: Incoming News

FLTK GUI bindings - Alpha release

Haskell on Reddit - Fri, 02/20/2015 - 8:19pm

I'm pleased to announce the alpha release of Haskell bindings to the FLTK GUI library.

On Linux and Mac this package and FLTK 1.3.3 should install pretty smoothly.

The library covers about 80+% of API and has 60+ widgets that can be used transparently from Haskell.

You can read more about the motivation behind the library, installation instructions and quick start documentation here.

The package also comes with 14 demos to show you how to get started.

There still isn't any support for Windows because I don't have access to a Windows machine, and don't have any experience with the Windows C/C++ build tools. The code itself should be fully portable. I could use some help here.

Please report any issues on the Github page.

Hope you enjoy and I'd love any feedback on the install and development process.

submitted by deech
[link] [6 comments]
Categories: Incoming News