[Help] How to input string in Haskell for mac?

[Help] How to input string in Haskell for mac?

Hi guys, I'm a noob to haskell coming for python and I would like to learn the language. However, I wanted to test some interactive programs so that I could practice somewhere that uses input and output like codechef and hackerrank. I'm looking for the equivalent to input() in python using Haskell for mac.

let main = do putStrLn "Greetings! What is your name?" inpStr <- getLine putStrLn $"Welcome to Haskell, " ++ inpStr ++ "!" main 

But I keep getting the error: Exception: <stdin>: hGetLine: illegal operation (handle is closed)

Any ideas?

Submitted June 24, 2017 at 08:32PM by jadenpls
via reddit http://ift.tt/2s2HsGf

What do Algebraic properties of the ADTs give/teach us?

What do Algebraic properties of the ADTs give/teach us?

I want to explain to my colleagues what do Algebraic properties of the ADTs give/teach us.

This is what I came up with yet:

Symmetry is the proof, that the order of the arguments in data constructors doesn't matter. Pair Int String ~= Pair String Int

Associativity is kind of proof that you shouldn't nest structures if you don't need to: Pair Int (Pair Bool String) ~= Triple Int Bool String

Identity says you don't need bigger data structure then the data you want to hold: Triple Bool Int () ~= Tuple Bool Int

am I correct?

Submitted June 23, 2017 at 08:58PM by notgiorgi
via reddit http://ift.tt/2tD15Si

Interfacing with vendor C++ library

Interfacing with vendor C++ library

There's a vendor C++ API that I normally use from C++ client code. I would like to use the API from Haskell. The API basically consists of some functions that the API client can call and the client needs to provide an object of a class implementing some interface that has callback functions that the API will call, from threads that the API creates on its own. The callbacks are used to communicate results of previous requests by the client and details of various types of events.

I don't care for the gratuitous use of threads by the API and would rather it sent me results using message queues and semaphores. How can I design a Haskell binding for this API where the callbacks are translated into items added to a message queue that the Haskell client can read in both blocking and non-blocking mode? I don't mind writing some helper C++ classes and functions.

For wrapping the callbacks, I thought of storing the queue items in C++ and providing functions that Haskell can use to peek and pop the next item, but I need a way for the C++ code to notify the Haskell when the queue becomes non-empty, so that Haskell code can do blocking reads or wait for the queue to become non-empty. I could use a Posix semaphore or something similar, but I'm not sure how to share a semaphore between C++ and Haskell. There's System.Posix.Semaphore but I don't want to rely on magical naming conventions for the semaphore names.

How can I design a blocking message queue that can be written from C++ and peek/read from Haskell? How can I design for the opposite direction? Are there example hackage packages that provide bindings for C++ APIs that also communicate to the client using callbacks from arbitrary threads?

Submitted June 22, 2017 at 11:21PM by Syncopat3d
via reddit http://ift.tt/2s0dW44