News aggregator

The sad thing is, you don't see the new stuff.

haskell-cafe - Tue, 07/07/2015 - 6:52pm
Haskell was - maybe - the most elegant mathematical logic-oriented language out there. It's why I used it. Now there is my approach, which is reciprocal simplification of the programming process. THAT is elegant. Cheers _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

You know, I am tired of it.

haskell-cafe - Tue, 07/07/2015 - 6:39pm
Whatever "community" I go, they all pretend like their old shit is SO important. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Reading and writing from a Socket without closing the handle

Haskell on Reddit - Tue, 07/07/2015 - 6:18pm

Hi guys, I'm trying to read/write a socket without having to close the handle. However, it seems like whatever I do, I cannot read the socket contents until the handle is closed.

Client code:

import Network.Socket import Network.BSD import Control.Monad import System.IO as IO import Data.Text as T import Data.ByteString.Lazy as BSL import Data.MessagePack as MP main = withSocketsDo $ do sock <- socket AF_INET Stream 0 setSocketOption sock ReuseAddr 1 addr <- liftM hostAddresses $ getHostByName "localhost" connect sock $ SockAddrInet (fromInteger 8585) (Prelude.head addr) handle <- socketToHandle sock ReadWriteMode hSetBuffering handle NoBuffering replicateM_ 5 $ BSL.hPut handle $ MP.pack ("Hello host" :: Text) hFlush handle getLine replicateM_ 5 $ BSL.hPut handle $ MP.pack ("Hello host" :: Text) hFlush handle hClose handle

Server code:

import Network.Socket import Network.Socket.ByteString as NSB import Network.Socket.ByteString.Lazy as NSBL import Data.MessagePack as MP import Data.Text as T import Data.ByteString.Lazy as BSL import Data.ByteString as BS import Data.HashMap as HM import System.IO as IO runServer :: Integer -> IO () runServer port = withSocketsDo $ do sock <- socket AF_INET Stream 0 setSocketOption sock ReuseAddr 1 bindSocket sock (SockAddrInet (fromInteger port) iNADDR_ANY) listen sock 100 servLoop sock servLoop :: Socket -> IO () servLoop sock = do connection <- accept sock onConnect connection servLoop sock onConnect :: (Socket, SockAddr) -> IO () onConnect (client, client_addr) = do IO.putStrLn "Got a connection" h <- socketToHandle client ReadWriteMode hSetBuffering h NoBuffering req <- BSL.hGet h 1024 IO.putStrLn "Got some contents: " IO.putStrLn $ show req

So the observed behavior is that the line

req <- BSL.hGet h 1024

doesn't evaluate until AFTER the client closes the handle. Is there a reason for that? and can I just have it continually stream data without closing the handle?

submitted by fuzzyslippers42
[link] [8 comments]
Categories: Incoming News

How to learn Haskell

Haskell on Reddit - Tue, 07/07/2015 - 11:07am

Can any one tell me how to start learning Haskell? Any series of tutorials i tired but unable to find quality tutorials. That is might be because Haskell is not a popular language like others.

submitted by mu_livecodingtv
[link] [5 comments]
Categories: Incoming News

Generalizing replicateM?

libraries list - Tue, 07/07/2015 - 8:56am
I noticed that traceM is generalized to use Applicative. Then, how about replicateM/replicateM_? I don't quite like confusing names, but is better than needlessly restrictive. _______________________________________________ Libraries mailing list Libraries< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Categories: Offsite Discussion

Why isn't there more emphasis on using (=<<) instead of (>>=)?

Haskell on Reddit - Tue, 07/07/2015 - 8:38am

Typically, when people explain monads, they begin with (>>=) and how it is used in desugaring the do notation. However, I've always found this very confusing because the data flows in the opposite direction from normal function application. Even LYAH only mentions (>>=).

I believe it is a good way to explain the different kinds of function applications by showing the following progression:

For a normal function

incByOne :: Int -> Int incByOne = (+1)

we apply it to the value twice as either

incByOne (incByOne 1) > 3

or using ($)

incByOne $ incByOne $ 1 > 3

We can apply the function to a value in functor context using (<$>)

incByOne <$> incByOne <$> Just 1 > Just 3

EDIT. As rightly pointed out by /u/imz , the above should be written as

incByOne <$> (incByOne <$> Just 1)

because (<$>) is left associative. See stack overflow question. Basically, my original example really is (incByOne <$> incByOne) <$> Just 1 and it only worked because -> is a functor.

ENDofEDIT.

Finally, we create a monadic version

incByOneM :: Int -> Maybe Int incByOneM n = if (n > 0) then Just $ n + 1 else Nothing

and we can apply it to the value in a monadic context

incByOneM =<< incByOneM =<< Just 1 > Just 3 incByOneM =<< incByOneM =<< Just (-1) > Nothing

Furhermore, we can mix the monadic and the non-monadic version as follows:

incByOneM =<< incByOne <$> Just 1 > Just 3 incByOne <$> (incByOneM =<< Just 1) > Just 3

Only after that explanation, I believe it is instructive to introduce (>>=) by saying that it inverses the dataflow (from left to right) as follows:

Just 1 >>= incByOneM >>= incByOneM > Just 3

Comments? Do you find it useful? Any existing resources using this style of explanation?

EDIT2: It seems the conclusion from the discussion is that supporting dataflow from left-to-right and right-to-left equally well is needed. To make all examples from this question equally well expressible using the left-to-right way, we can use the & operator:

incByOne $ incByOne $ 1 1 & incByOne & incByOne

However, there's no standard operator for values in the functor context. Probably a good analogue could be <&>:

incByOne <$> (incByOne <$> Just 1) (Just 1 <&> incByOne) <&> incByOne

EDIT5: /u/Peaker pointed out that &, <&>, and >>= are all left associative, so no parentheses needed for

Just 1 <&> incByOne <&> incByOne

/u/ForTheFunctionGod has even created a package with a set of operators for functors.

And, for values in monadic context we have

incByOneM =<< incByOneM =<< Just 1 Just 1 >>= incByOneM >>= incByOneM

So, the question is: has anybody considered adding something like <&> to base?

ENDofEDIT2

EDIT3: /u/mightybyte has been introducing monads this way for a long time, precisely to make an analogy with ($).

EDIT4: both (&) and (<&>) are defined in Control.Lens.Operators but it would be really great to have them both in base.

EDIT5: CONCLUSION.

Thanks everybody for your insights. I've learned quite a lot here. Here's my summary after applying both styles (left-to-right and right-to-left) in my code.

Using $, <$>, and =<< + applicative

This was my style. These operators shine in two cases:

[+] with datatype constructors (and applicative style)

Person <$> getFirstName <*> getLastName

because it keeps the same shape as the datatype:

data Person = Person String String

[+] point free style

let f = incByOne $ incByOne

instead of

let f n = incByOne $ incByOne n

However, problems arise due to mixed infixity, since <$> is left associative whereas $ and =<< are right associative.

[-] requires careful placement of brackets

incByOne <$> (incByOne <$> Just 1) Using &, <&>, and >>=

These really shine in two cases:

[+] creating a pipe through which data flows left-to-right (which follows the direction of -> in type definition)

1 & Just <&> incByOne >>= incByOneM

no brackets needed here since all of them are left-associative and have the same infixity (1).

[+] applying multiple modifications to the same object. This is particularly nice with lenses:

Person "Alic" "Bck" & name .~ "Alice" & lastName .~ "Black"

Two downsides:

[-] have to import Control.Lens ((&), (<&>))

[-] cannot use them point-free style

submitted by mallai
[link] [49 comments]
Categories: Incoming News

New Haskellers: Ask Anything

Haskell on Reddit - Tue, 07/07/2015 - 7:44am

As we agreed 19 days ago, here it is.

submitted by clrnd
[link] [509 comments]
Categories: Incoming News

Stack + ghc-mod: work in progress

Haskell on Reddit - Tue, 07/07/2015 - 6:58am

ajnsit on Github has made a lot of progress towards getting ghc-mod work with stack.

I had a few bugs (package-db paths had trailing newlines) which I fixed in my version of the repo.

I just got ghc-mod working on my desktop by following the following steps:

git clone https://www.github.com/parsonsmatt/ghc-mod cd ghc-mod && git checkout stack-support stack install

I'm now able to do type inspection with vim on all my stack projects :D

I'd appreciate if others could give it a shot and report their experiences, either here or on Github.

submitted by ephrion
[link] [10 comments]
Categories: Incoming News

GHC Memory Management wiki page

haskell-cafe - Tue, 07/07/2015 - 5:54am
I have been studying the garbage collection algorithms used in GHC, and it appears to me that section two of [1] is misleading, since thunks permit controlled mutation of the heap, and so objects in older generations may point to younger objects. In fact, the RTS maintains "remembered sets" to keep track of these relations. A Haskell could in principle be implemented in the way described (and execute in surprising complexity classes), but this does not seem to match reality. [1] https://wiki.haskell.org/GHC/Memory_Management Should the wiki be modified? Regards, Kyle Miller _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

I print myself

Haskell on Reddit - Tue, 07/07/2015 - 3:06am
main=putStr$(\x->x++show x)"main=putStr$(\\x->x++show x)" submitted by Florian939
[link] [12 comments]
Categories: Incoming News

Strange "ambiguity" problems thanks to GADTs

haskell-cafe - Tue, 07/07/2015 - 1:28am
Hi all, In my latest project I've been using a bunch of GADTs, which unfortunately disables let-polymorphism (i.e., where-polymorphism) in the most annoying way. For the most part I've been able to hack around that limitation via judicious use of ScopedTypeVariables, but I've run into an issue that I can't for the life of me figure out why GHC doesn't like it. I have something like the following function, where < at >a< at > and < at >b< at > happen to be GADTs: foo :: (A a, B b) => a i -> M (b i) foo a = case view a of ... SomePattern a1 a2 -> do b1 <- foo a1 b2 <- foo a2 return . unview $ SomePattern b1 b2 It seems to me that the recursive calls should work just fine, using the same < at >b< at > as we'll ultimately be returning. However, for some reason GHC complains about the recursive calls using some other < at >b0< at > can can't deduce < at >B b0< at > from < at >B b< at >. Why doesn't GHC unify these two types? How can I force them to unify without adding type annotations at every recurs
Categories: Offsite Discussion

Is Greece a Monad?

Haskell on Reddit - Mon, 07/06/2015 - 11:21pm

Is it a monad, in the sense that it binds all the money and returns ()? I am Greek so feel free to write anything you like...

submitted by nikosquant
[link] [comment]
Categories: Incoming News

Request for maintainer(s) : language-javascript /hjsmin

haskell-cafe - Mon, 07/06/2015 - 7:42pm
Hi all I am the author of language-javascript and its companion hjsmin. Unfortunately I do not use the libraries myself, and I am falling behind in maintaining them, all the more so with the new ECMASCRIPT spec out. So I am calling for volunteers to take over maintenance of these two packages. Regards Alan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

OCL 2015: Final Call for Papers - Only 10 Days Left

General haskell list - Mon, 07/06/2015 - 7:12pm
(Apologies for duplicates) If you are working on the foundations, methods, or tools for OCL or textual modelling, you should now prepare your submission for the OCL workshop! CALL FOR PAPERS 15th International Workshop on OCL and Textual Modeling Tools and Textual Model Transformations Co-located with ACM/IEEE 18th International Conference on Model Driven Engineering Languages and Systems (MODELS 2015) September 28th, 2015, Ottawa, Canada http://ocl2015.lri.fr Modeling started out with UML and its precursors as a graphical notation. Such visual representations enable direct intuitive capturing of reality, but some of their features are difficult to formalize and lack the level of precision required to create complete and unambiguous specifications. Limitations of the graphical notations encouraged the development of text-based modeling languages that either integrate with or replace graphical notations for modeling. Typical examples of su
Categories: Incoming News

OCL 2015: Final Call for Papers - Only 10 Days Left

haskell-cafe - Mon, 07/06/2015 - 7:12pm
(Apologies for duplicates) If you are working on the foundations, methods, or tools for OCL or textual modelling, you should now prepare your submission for the OCL workshop! CALL FOR PAPERS 15th International Workshop on OCL and Textual Modeling Tools and Textual Model Transformations Co-located with ACM/IEEE 18th International Conference on Model Driven Engineering Languages and Systems (MODELS 2015) September 28th, 2015, Ottawa, Canada http://ocl2015.lri.fr Modeling started out with UML and its precursors as a graphical notation. Such visual representations enable direct intuitive capturing of reality, but some of their features are difficult to formalize and lack the level of precision required to create complete and unambiguous specifications. Limitations of the graphical notations encouraged the development of text-based modeling languages that either integrate with or replace graphical notations for modeling. Typical examples of su
Categories: Offsite Discussion