News aggregator

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

Why is GHC Runtime Enviornment in C?

Haskell on Reddit - Mon, 08/18/2014 - 3:11pm

I have been using haskell for about half a year, and one question that bothered me is why isn't the runtime of GHC written in haskell?

It seems that the language is capable of handling this task, and some other languages do (Common Lisp being one). I understand that there are some limitations to this, and OS specific tasks need to be handle natively. However, the rest could be haskell and not the daunting 50,000 lines of C.

submitted by Artemis311
[link] [31 comments]
Categories: Incoming News

Functional Programming Group at the University of Kansas: Bluetooth on Haskell

Planet Haskell - Mon, 08/18/2014 - 3:04pm
I'm presenting a very early draft of my bluetooth library. As its name suggests, bluetooth is a Haskell frontend to low-level Bluetooth APIs, making it similar in spirit to Python's PyBluez and Java's BlueCove.
What it can doCurrently, bluetooth only supports Linux. It has the capability of running an RFCOMM server and client. Theoretically, it should also support L2CAP servers and clients, although this has not been tested yet.
What it will eventually doI plan to have bluetooth support each of the GHC Tier 1 platforms—that is, Windows, OS X, Linux, and FreeBSD. I want to have the capability to run the full gamut of L2CAP and RFCOMM-related functions on each OS, as well as any additional OS-specific functionality.
MotivationBluetooth programming on Haskell is currently in a very primitive state. As of now, there are only two packages on Hackage that make any mention of Bluetooth (as far as I can tell):

  1. network hints in its Network.Socket module that there is an AF_BLUETOOTH socket address family. However, trying to use it with network will fail, since there is no corresponding Bluetooth SockAddr.
  2. simple-bluetooth by Stephen Blackheath offers some of what my own bluetooth package offers (namely, RFCOMM client capability on Windows and Linux).
However, there is currently no comprehensive, cross-platform Haskell Bluetooth library à la PyBluez or BlueCove. I want bluetooth to fill that niche.
How bluetooth worksbluetooth can be thought of as a wrapper around network. After all, Bluetooth programming is socket-based, so Network.Socket already provides most of what one needs to implement a Bluetooth server or client. There are several gotchas with Bluetooth programming, however:
  • Every major OS has a completely different Bluetooth software stack. For example, Linux uses BlueZ, and Windows has several different stacks, including Winsock and Widcomm. Therefore, bluetooth is not likely to work identically on every OS.
  • Windows in particular is challenging to support since several Winsock functions do not work correctly on the version of MinGW-w64 that is currently shipped with GHC for Windows (only the 64-bit version, no less). For this reason, I probably won't develop a Windows version of bluetooth until this issue is resolved.
It is recommended that you have a basic understanding of Bluetooth programming before attempting to use bluetooth. I recommend this introduction by Albert Huang.
ExamplesThe following are abridged examples of the RFCOMM client and server examples from the bluetooth repo.
RFCOMM servermodule Main where
import Data.Set

import Network.Bluetooth
import Network.Socket

main :: IO ()
main = withSocketsDo $ do
let uuid = serviceClassToUUID SerialPort
proto = RFCOMM
settings = defaultSDPInfo {
sdpServiceName = Just "Roto-Rooter Data Router"
, sdpProviderName = Just "Roto-Rooter"
, sdpDescription = Just "An experimental plumbing router"
, sdpServiceClasses = singleton SerialPort
, sdpProfiles = singleton SerialPort

handshakeSock <- bluetoothSocket proto
btPort <- bluetoothBindAnyPort handshakeSock anyAddr
bluetoothListen handshakeSock 1
service <- registerSDPService uuid settings proto btPort
(connSock, connAddr) <- bluetoothAccept handshakeSock
putStrLn $ "Established connection with address " ++ show connAddr

message <- recv connSock 4096
putStrLn $ "Received message! [" ++ message ++ "]"
let response = reverse message
respBytes <- send connSock response
putStrLn $ "Sent response! " ++ show respBytes ++ " bytes."

close connSock
close handshakeSock
closeSDPService service
RFCOMM clientmodule Main where

import Network.Bluetooth
import Network.Socket

import System.IO

main :: IO ()
main = withSocketsDo $ do
let addr = read "12:34:56:78:90:00"
port = 1

sock <- bluetoothSocket RFCOMM
bluetoothConnect sock addr port
putStrLn "Established a connection!"

putStr "Please enter a message to send: "
hFlush stdout
message <- getLine

messBytes <- send sock message
response <- recv sock 4096
putStrLn $ "Received reponse! [" ++ reponse ++ "]"

close sock
<script type="text/javascript"> SyntaxHighlighter.highlight(); </script>
Categories: Offsite Blogs

Fully funded PhD position on Computational Logic/Functional Programming/Interactive Theorem Proving, University of Dundee, Scotland

haskell-cafe - Mon, 08/18/2014 - 9:45am
One fully funded PhD position on Computational Logic/Functional Programming/Interactive Theorem Proving is available at the University of Dundee, Scotland. For more information, please email katya< at > or refer to: The funding is provided by EPSRC Doctoral Training Partnership Scheme, and is available for UK residents only. Katya Ekaterina Komendantskaya Senior Lecturer, Head of PhD Studies Room 1.04, Queen Mother Building School of Computing, University of Dundee Scotland, DD14HN Tel: (+44) 01382384820 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

CUFP 2014: Call For Participation

General haskell list - Mon, 08/18/2014 - 9:16am
****************************************************************** CALL FOR PARTICIPATION Commercial Users of Functional Programming (CUFP) 2014 at ICFP 2014; Gothenburg, Sweden, Sep 4-6. ****************************************************************** Overview ======== Functional programming has been at the forefront of a new generation of programming technologies: Companies employing functional programming use it to enable more effective, robust, and flexible software development. The annual CUFP workshop is designed to serve the growing community of commercial users of functional programming: Practitioners meet and collaborate; language designers and users can share ideas about the future of their languages; experts share their expertise on practical functional programming. CUFP 2014 begins with two days of tutorials by top-notch language experts including advanced tutorials on special topics, followed by a day of talks about industrial applications of functional programming.
Categories: Incoming News

JP Moresmau: Fame at last!

Planet Haskell - Mon, 08/18/2014 - 9:10am
I was reading the book "Haskell Data Analysis Cookbook" when suddenly, my name pops up! Funny to see a link to a 7 year old blog entry, who knew I would go down in history for a few line of codes for a perceptron? It's deep in Chapter 7, for those interested. Maybe this is a sign that I should abandon everything else and spend my time on AI, since it's obviously where fame and riches abound! Right...

Categories: Offsite Blogs