News aggregator

Safer Haskell Install

Haskell on Reddit - Wed, 08/20/2014 - 12:40am
Categories: Incoming News

Locking of threads in one OS thread

haskell-cafe - Tue, 08/19/2014 - 10:36pm
Hello Cafe, I'm using FFI to interact with a library which calls, when fail, leave the reason in some kind of "errno"-like variable which is retrived via another call. AFAIU, this is not thread-safe in Haskell even if thread-local storage is used inside the library, because Haskell uses its own thread management and the Haskell thread in the same OS thread might be switched between the actual call and the retrival of errno value. This should be somehow handled already in Haskell (errno is widely used with syscalls in Linux, for example), but the source of Foreign.C.Error suggests that this is not handled in any way at all. For example, throwErrnoIf is implemented as such: throwErrno loc = do errno <- getErrno ioError (errnoToIOError loc errno Nothing Nothing) throwErrnoIf pred loc f = do res <- f if pred res then throwErrno loc else return res So, the question is: how is it ensured that this block is "atomic" in sense that at most one Haskell thread computes this whole function at every
Categories: Offsite Discussion

Reducing CPU load when using Helm

haskell-cafe - Tue, 08/19/2014 - 7:08pm
Forwarding this to haskell-cafe as it failed before. On 18 August 2014 20:24, Kaspar Emanuel <kaspar.bumke< at >> wrote:
Categories: Offsite Discussion

Deprecating yesod-platform

Haskell on Reddit - Tue, 08/19/2014 - 6:55pm
Categories: Incoming News

Code Review For My Library 'spice'?

Haskell on Reddit - Tue, 08/19/2014 - 4:49pm

I've just "finished" (in quotes because I'm still very heavily developing it, but it technically functional enough to use) my first published library in Haskell. Its name is spice. It's meant to provide the ability to quickly set up GLFW with Elerea.

It's hosted on hackage and GitHub (with GitHub tending to have updated code). Despite it working, I'm feeling rather insecure about the degree to which the code is optimal and idiomatic. Since this subreddit is seemingly filled with Haskell geniuses, I was wondering if any of you would be willing to take a look at my code and help me try to better both it and myself as a Haskell programmer.

Thank you so much!

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

is there any way to generalize this function to all Functors

Haskell on Reddit - Tue, 08/19/2014 - 4:34pm

ideally the type signature would be (Functor f, Monad m) => f a -> (a -> m b) -> m (f b) but i have no idea how to do this or even if it's possible

shit :: (Monad m) => Maybe a -> (a -> m b) -> m (Maybe b) shit (Just a) f = f a >>= return . Just shit Nothing _ = return Nothing shit' :: Monad m => [a] -> (a -> m b) -> m [b] shit' xs f = mapM f xs shit'' :: Monad m => (x, a) -> (a -> m b) -> m (x, b) shit'' (x, a) f = do b <- f a return (x, b) submitted by Intolerable
[link] [12 comments]
Categories: Incoming News

Proposal: Add forkOSUnmasked to Control.Concurrent

libraries list - Tue, 08/19/2014 - 1:24pm
Joey Adams wrote a request a year or so ago to add forkOSUnmasked to Control.Concurrent
Categories: Offsite Discussion

Category with fanout (&&&) and split (***) but not an arrow: is there a name?

Haskell on Reddit - Tue, 08/19/2014 - 12:47pm

Recently I've been developing a representation of circuits in the style of the operational monad. My circuit datatype (parameterized by a type of primitive component) forms a category with the "wire" Circuit f a a forming the identity, and sequential composition of circuits the category composition.

But in addition to the category structure, I have equivalents to the fanout (&&&) and split (***) operators from Control.Arrow, and it's from here that my question comes. I cannot support the arr operator, because it's impossible to lift an arbitrary function into my type, but otherwise, it is very "arrow-like" (as described above). Is there a name for this variety of additional structure on a category? Have I partially reinvented pieces of a more powerful abstraction?

For reference, here's a version of my datatype, simplified to elide some irrelevant type-hackery and complexity.

data Circuit c x y where Lift :: c x y -> Circuit c x y Wire :: Circuit c x x (:>>>) :: Circuit c x y -> Circuit c y z -> Circuit c x z (:&&&) :: Circuit c x y -> Circuit c x z -> Circuit c x (y,z) (:***) :: Circuit c w x -> Circuit c y z -> Circuit c (w,y) (x,z) submitted by kwef
[link] [69 comments]
Categories: Incoming News

Brent Yorgey: Maniac week postmortem

Planet Haskell - Tue, 08/19/2014 - 12:18pm

My maniac week was a great success! First things first: here’s a time-lapse video1 (I recommend watching it at the full size, 1280×720).

<iframe class="youtube-player" frameborder="0" height="315" src=";rel=1&amp;fs=1&amp;showsearch=0&amp;showinfo=1&amp;iv_load_policy=1&amp;wmode=transparent" type="text/html" width="560"></iframe>

Some statistics2:

  • Total hours of productive work: 55.5 (74 pings)
  • Average hours of work per day3: 11
  • Average hours of sleep per night: 7.8 (52 pings over 5 nights)4
  • Total hours not working or sleeping: 27.25 (37 pings)
  • Average hours not working per day: 5.5
  • Pages of dissertation written: 24 (157 to 181)

[I was planning to also make a visualization of my TagTime data showing when I was sleeping, working, or not-working, but putting together the video and this blog post has taken long enough already! Perhaps I’ll get around to it later.]

Overall, I would call the experiment a huge success—although as you can see, I was a full 2.5 hours per day off my target of 13.5 hours of productive work each day. What with eating, showering, making lunch, getting dinner, taking breaks (both intentional breaks as well as slacking off), and a few miscellaneous things I had to take care of like taking the car to get the tire pressure adjusted… it all adds up surprisingly fast. I think this was one of the biggest revelations for me; going into it I thought 3 hours of not-work per day was extremely generous. I now think three hours of not-work per day is probably within reach for me but would be extremely difficult, and would probably require things like planning out meals ahead of time. In any case, 55 hours of actual, focused work is still fantastic.

Some random observations/thoughts:

  • Having multiple projects to work on was really valuable; when I got tired of working on one thing I could often just switch to something else instead of taking an actual break. I can imagine this might be different if I were working on a big coding project (as most of the other maniac weeks have been). The big project would itself provide multiple different subtasks to work on, but more importantly, coding provides immediate feedback that is really addictive. Code a new feature, and you can actually run the new code! And it does something cool! That it didn’t do before! In contrast, when I write another page of my dissertation I just have… another page of my dissertation. I am, in fact, relatively excited about my dissertation, but it can’t provide that same sort of immediate reinforcing feedback, and it was difficult to keep going at times.

  • I found that having music playing really helped me get into a state of “flow”. The first few days I would play some album and then it would stop and I wouldn’t think to put on more. Later in the week I would just queue up many hours of music at a time and that worked great.

  • I was definitely feeling worn out by the end of the week—the last two days in particular, it felt a lot harder to get into a flow. I think I felt so good the first few days that I became overconfident—which is good to keep in mind if I do this again. The evening of 12 August was particularly bad; I just couldn’t focus. It might have been better in the long run to just go home and read a book or something; I’m just not sure how to tell in the moment when I should push through and when it’s better to cut my losses.

  • Blocking Facebook, turning off email notifications, etc. was really helpful. I did end up allowing myself to check email using my phone (I edited the rules a few hours before I started) and I think it was a good idea—I ended up still needing to communicate with some people, so it was very convenient and not too distracting.

  • Note there are two places on Tuesday afternoon where you can see the clock jump ahead by an hour or so; of course those are times when I turned off the recording. One corresponded to a time when I needed to read and write some sensitive emails; during the other, I was putting student pictures into an anki deck, and turned off the recording to avoid running afoul of FERPA.

That’s all I can think of for now; questions or comments, of course, are welcome.

  1. Some technical notes (don’t try this at home; see for some recommendations on making your own timelapse). To record and create the video I used a homegrown concoction of scrot, streamer, ImageMagick, ffmpeg, with some zsh and Haskell scripts to tie it all together, and using diagrams to generate the clock and tag displays. I took about 3GB worth of raw screenshots, and it takes probably about a half hour to process all of it into a video.

  2. These statistics are according to TagTime, i.e. gathered via random sampling, so there is a bit of inherent uncertainty. I leave it as an exercise for the reader to calculate the proper error bars on these times (given that I use a standard ping interval of 45 minutes).

  3. Computed as 74/(171 – 9) pings multiplied by 24 hours; 9 pings occurred on Sunday morning which I did not count as part of the maniac week.

  4. This is somewhat inflated by Saturday night/Sunday morning, when I both slept in and got a higher-than-average number of pings; the average excluding that night is 6.75 hours, which sounds about right.

Categories: Offsite Blogs

Is there something for emacs to view project modulestructure?

haskell-cafe - Tue, 08/19/2014 - 10:20am
Hi, I think a structure viewing in editor could be very help for long file or big project. Something like java/c# IDEs do. But I could not find a hint on google. Any suggestions?
Categories: Offsite Discussion

[ANN] extended-categories

haskell-cafe - Tue, 08/19/2014 - 8:36am
extended-categories <> is an implementation of categories designed to make use of GHC's recently enriched kind system. This project is a work in progress (only a few basic constructs are implemented), but your comments are welcomed. extended-categories requires a recent version of GHC (I have only tested it with 7.8.3). Categories are poly-kinded and have an Object constraint family: class Category m where type Object (m :: k -> k -> *) (a :: k) :: Constraint id :: Object m a => m a a (.) :: (Object m a, Object m b, Object m c) => m b c -> m a b -> m a c This means in addition to our usual categories of kind * -> * -> * we can define categories of other kinds, for example (:-) from the constraints package forms a category with kind Constraint -> Constraint -> * (whose instance is used in this package)! Functors are named (tagged) as done in the data-category package. This allows a much wider variety of functors to be defined. Additionally functors must pro
Categories: Offsite Discussion


libraries list - Tue, 08/19/2014 - 8:09am
David You've been doing all this work on improving fusion, and you probably have a very good idea now about how it works, and how GHC's libraries use phases and RULES to achieve it. A kind of design pattern, if you like; tips and tricks. I wonder if you'd feel able to write a GHC wiki page describing what you have learned, with examples and explanation about why it is done that way. If you did this, someone who follows in your footsteps wouldn't need to re-learn everything. And maybe someone will say "oh, there's one pattern you have omitted, here it is". Thanks Simon
Categories: Offsite Discussion

and / or

libraries list - Tue, 08/19/2014 - 7:24am
First question: how bad would it be to use the Prelude definitions of and and or? I assume if there's a problem it's probably excessive duplication by the inliner? Second question: if that would be bad, why not rewrite them to foldr forms, then write them back, like other things do? Statement: if the current arrangement really is the best, then we should add two additional rules: "and/augment" forall (g::forall b.(Bool->b->b)->b->b) (xs::[Bool]) . and (augment g xs) = g (&&) (and xs) "or/augment" forall (g::forall b.(Bool->b->b)->b->b) (xs::[Bool]) . or (augment g) = g (||) (or xs)
Categories: Offsite Discussion

Do you or how do you use object-based programming in Haskell?

Haskell on Reddit - Tue, 08/19/2014 - 1:41am

Should this topic be moved to /r/haskellquestions? Someone please help me! ಠ_____ಠ

To design bigger programs, or to solve more complicated problem, we usually divide them into smaller parts and solve them individually. And OBP or OOP are most famous design patterns.

Here comes the problem, how do we use something like OBP in Haskell?

[Edit] 19 Aug

Don't get me wrong. I'm saying object-based, not object-oriented. Object-oriented (not definitional) means everything is an object. I just want to use some object to pack things into a whole.

Although we are doing FP, we'll still have to be faced with the side effect things. Especially when in some realtime/long-term/interactive programs, there comes more side effects.

Two different implementation I find are

1) I call the following C++ style

module Something.Counter ( Counter, newCounter, counterIncrement, counterReset ) where -- hiding "counterNumber" as private member import xx data Counter = Counter { counterNumber :: IORef Int } newCounter :: IO Counter newCounter = return $ Counter (newIORef (0 :: Int))) counterIncrement :: Counter -> IO () counterIncrement counter = modifyIORef' (counterNumber counter) (+1) counterReset :: Counter -> IO () counterReset counter = writeIORef (counterNumber counter) 0

(2) I call the following JavaScript style (or closure style, maybe)

module Something.Counter where import xx data Counter = Counter { counterIncrement :: IO () counterReset :: IO () } newCounter :: IO Counter newCounter = do number <- newIORef (0 :: Int) let increment = modifyIORef' number (+1) let reset = writeIORef number 0 return Counter { counterIncrement = increment counterReset = reset }

(The latter may use more memory in some cases, but also easier to write sometime.)

(You may ask why I prefer to use this imperative style in such a simple Counter. This is just a example to make me better understood. For some real example, I would pick something like hash-table which is born non-funtional. )

But both implementation have the problem: you will need to write something like

counterIncrement counter

compare this with other imperative OOP languages


Think about this

dog.getLeg(1).getToe(2) dogLegToe (dogLeg dog 1) 2

The syntax will be complicated and names will get longer and longer (and you won't want to use TypeClass here).

So object-based programming in Haskell is not easy. How do you do the encapsulation? Did I get something wrong or do you NOT use OBP at all?

submitted by RnMss
[link] [56 comments]
Categories: Incoming News

Guard expression over a range, is it possible?

Haskell on Reddit - Tue, 08/19/2014 - 1:30am

Okay, so I have a list of Integers, which I want to convert into chars, however, it's not in ASCII, it's a custom mapping. Is it possible to say,

[convertChar x | x <- intsIn]

where convertChar is something like

convertChar :: Integer -> Maybe Char convertChar a | a isElementOf [0..25] = Just (chr (a + ord 'A')) | a isElementOf [26..51] = Just (chr (a - 26 + ord 'a')) | a isElementOf [52..61] = Just (chr (a - 52 + ord '0')) | a == 62 = Just '+' | a == 63 = Just '/' | otherwise = Nothing

yes that's base64

Also, should I be using Maybe's, or throwing Exceptions?

Also, will the compiler make the ranges staticly generated, or will it recreate them every function call?

(edit 14-08-19)_________________________________________________________________________

Okay, list membership function == elem So,

convertChar a | a `elem` [0..25] = Just (chr (a + ord 'A')) | a `elem` [26..51] = Just (chr (a - 26 + ord 'a')) | a `elem` [52..61] = Just (chr (a - 52 + ord '0')) | a == 62 = Just '+' | a == 63 = Just '/' | otherwise = Nothing

So that's Question 1 solved.

Oh, and

prettyPrintBase64 :: [Int] -> String prettyPrintBase64 intsIn = catMaybes [prettyPrintBase64Char c | c <- intsIn]

also, whoops, forgot the Just declarations...

submitted by nayru25
[link] [18 comments]
Categories: Incoming News

Type-level numbers problem

haskell-cafe - Mon, 08/18/2014 - 8:15pm
Hi! I wrote one thing with type-level numbers that were represented as simple data Zero data Succ a Then, in order to not invent my own peano numbers, I decided to go look for ones, and found GHC.TypeLits. But unfortunately, it shows a weird error for me. Here is a piece of code: The one that's below "main" is working properly, while the one on top of it gives this error: typenats.hs:17:16: No instance for (Op D (0 + 1)) arising from a use of `f' Possible fix: add an instance declaration for (Op D (0 + 1)) In the expression: f (VJ i :: VJ D (0 + 1)) In an equation for `f': f (VJ i) = f (VJ i :: VJ D (0 + 1)) In the instance declaration for `Op D 0' Maybe I worked too much on type-level numbers today to not understand this simple error I'm getting, but could someone be so kind and explain me what am I doing wrong? Thank you very much! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion