News aggregator

Database with similar type system to Haskell?

Haskell on Reddit - Tue, 11/25/2014 - 9:08am

Does anyone know of any database software with a similar type system to Haskell?

It'd be really cool if I could clearly see that some fields were of type Maybe Int - i.e. allow missing values, and some do not - and the database throws an error if those fields are omitted.

It'd be even better if it could apply regex checks to data entry too.

At the moment I'm using MongoDB at work, and the duck-typing on the fields is a nightmare, as it leads some IDs to be strings, and others to be ints, depending on if there are errors in the original files. Ideally I want these flagged up at entry time so I can fix it (I realise that a SQL database would help a lot with this but it wasn't my choice).

submitted by jamesmcm
[link] [40 comments]
Categories: Incoming News

LHC Team: Very minimal Hello World.

Planet Haskell - Tue, 11/25/2014 - 1:08am
The LLVM Haskell Compiler finally coming together. From Haskell parser to name resolution to type checker to desugarer to LLVM backend to GC. Everything is held together with duct tape but it feels great to finally compile and run Hello World.
# cat Hello.hs
{-# LANGUAGE MagicHash #-}
module Main (main) where

import LHC.Prim

main :: IO Unit
main =
puts "Hello Haskell!"# `thenIO`
return Unit

entrypoint :: Unit
entrypoint = unsafePerformIO main

Compiling the above file yields a single LLVM program, containing user code and the RTS.

# lli Hello.ll
Hello Haskell!
Categories: Offsite Blogs

Like "foldr" or "maybe" but for a single cons...

Haskell on Reddit - Mon, 11/24/2014 - 9:56pm

Does this have a name?

something :: b -> (a -> [a] -> b) -> [a] -> b something x _ [] = x something _ f (x:xs) = f x xs submitted by dllthomas
[link] [5 comments]
Categories: Incoming News

MFlow examples

del.icio.us/haskell - Mon, 11/24/2014 - 6:41pm
Categories: Offsite Blogs

Natural and Nat kinds

Haskell on Reddit - Mon, 11/24/2014 - 3:43pm

Will the new Natural type, when lifted as a kind (if/when that's possible), be the same as the Nat kind, or will they exists as different kinds?

submitted by AshleyYakeley
[link] [11 comments]
Categories: Incoming News

Haskell as a "hobby".

Haskell on Reddit - Mon, 11/24/2014 - 3:09pm

Yesterday I randomly bumped into Haskell and have been intrigued ever since. I’ve looked through introductory/intermediate videos and read into the first chapters of “Real World Haskell” and “Learn You a Haskell for Great Good”. From what I actually HAVE understood, I see that there is a lot of elegance and interesting aspects to the language. And I absolutely understand why Haskell has a reputation for a steep learning curve that can melt your brain. But I think that’s good!

Thing is, I don’t have a background in CS. I’m actually of the design type, just with a strong interest in technical stuff. I know my way around the elementary webtechnologies, have an interest in generative design and dabble with physical computing/Arduino. But all this is for pure fun. I would never call myself a programmer nor do I intend to make a living as one anytime in the future. I just think programming is kinda… relaxing. (After you overcome bouts of laptop-smashing frustration).

My current drug of choice is Processing, since it’s taylor-made for visual output which I aim at with generative design. “Duh!”, I hear you say, “how dare you compare this dumbed-down piece of Java with our excellent Haskell?!”. I know, I know… hear me out. For me programming is not about flexible, maintainable, high-quality software, but rather bringing my visual ideas to fruition. Often times with code so damn fugly, any self-respecting programmer would run to the woods and bite into a tree out of pure rage. But… I find Haskell so very intriguing. And I’d like to try and tackle it. But I don’t know if I should. Because I know I’ve just scratched the very surface of understanding the full power of the language and maybe what I want to do (mainly visual-centric output) is just batshit insane and/or overkill doing with Haskell.

As a reference, I’m currently working my way through Dan Shiffmans’ “Nature of Code”, learning all about physics systems, autonomous agents, fractals, simulation of evolution, etc. All as a means of finding new ways to create generative visuals.

So now I’m asking you, dearest community, if you could help me make a decision. Is it okay/sensible/sane of me to have a go at Haskell as fresh diversion from what I know through Processing? Maybe it can allow me to do things which are difficult/unthinkable with more traditional languages? Or am I on the completely wrong path?

Thanks for any feedback and opinions!

submitted by sevennationsalami
[link] [50 comments]
Categories: Incoming News

Gabriel Gonzalez: How to build library-agnostic streaming sources

Planet Haskell - Mon, 11/24/2014 - 8:56am

The Haskell ecosystem has numerous libraries for effectful stream programming, including, but not limited to:

  • List
  • conduit
  • enumerator
  • io-streams
  • iterIO
  • iteratee
  • list-t
  • logict
  • machines
  • pipes

Unfortunately, this poses a problem for library writers. Which streaming library should they pick when providing effectful streaming components?

Sometimes the correct answer is: none of the above! We can often build streaming and effectful generators using only the base and transformers libraries!

The trick is to build polymorphic generators using only the MonadPlus and MonadTrans type classes. These generators can then be consumed by any library that provides an implementation of ListT that implements MonadPlus and MonadTrans.

MonadPlus

I like to think of MonadPlus as the "list building" type class. This is because you can assemble a list using return, mzero, and mplus:

>>> import Control.Monad (MonadPlus(..))
>>> mzero :: [Int]
[]
>>> return 1 :: [Int]
[1]
>>> return 1 `mplus` return 2 :: [Int] -- [1] ++ [2]
[1, 2]

In other words, mzero is analogous to [], mplus is analogous to (++), and return builds a singleton list.

However, many things other than lists implement MonadPlus, including every implementation of ListT in the wild. Therefore, if we build collections using MonadPlus operations these collections will type-check as ListT streams as well.

Let's provide the following helper function to convert a list to this more general MonadPlus type:

select :: MonadPlus m => [a] -> m a
select [] = mzero
select (x:xs) = return x `mplus` select xs

-- or: select = foldr (\x m -> return x `mplus` m) mzero

Note that this select function has some nice mathematical properties:

select (xs `mplus` ys) = (select xs) `mplus` (select ys)
select mzero = mzero

-- This assumes the distributivity law for `MonadPlus`
select . (f >=> g) = (select . f) >=> (select . g)
select . return = returnMonadTrans

Using select and lift (from MonadTrans), we can build list comprehensions that interleave effects, like this:

example :: (MonadTrans t, MonadPlus (t IO)) => t IO ()
example = do
x <- select [1, 2, 3]
lift (putStrLn ("x = " ++ show x))
y <- select [4, 5, 6]
lift (putStrLn ("y = " ++ show y))

You can read the above code as saying:

  • Let x range from 1 to 3
  • Print x every time it selects a new value
  • For each value of x, let y range from 4 to 6
  • Print y every time it selects a new value

Notice how example doesn't depend on any particular streaming library, so we can run it with diverse ListT implementations, all of which implement MonadPlus and MonadTrans:

>>> Pipes.runListT example -- This requires `pipes-4.1.4`
x = 1
y = 4
y = 5
y = 6
x = 2
y = 4
y = 5
y = 6
x = 3
y = 4
y = 5
y = 6
>>> _ <- Control.Monad.Logic.observeAllT example
<Exact same output>
>>> _ <- ListT.toList example
<Exact same output>

However, we can use this trick for more than just list comprehensions. We can build arbitrary lazy and effectful streams this way!

Generators

Here's an example of a generator that lazily emits lines read from standard input:

import Control.Monad (MonadPlus(..))
import Control.Monad.Trans.Class (MonadTrans(..))
import System.IO (isEOF)

stdinLn :: (MonadTrans t, MonadPlus (t IO)) => t IO String
stdinLn = do
eof <- lift isEOF
if eof
then mzero
else lift getLine `mplus` stdinLn

You can read the above code as saying:

  • Check if we are at the end of the file
  • If we're done, then return an empty list
  • If we're not done, prepend a getLine onto a recursive call to stdinLn

We can prove this works by writing a program that forwards these lines to standard output:

echo :: (MonadTrans t, MonadPlus (t IO)) => t IO ()
echo = do
str <- stdinLn
lift (putStrLn str)

Now we can run echo using any of our favorite ListT implementations and it will do the right thing, streaming lines lazily from standard input to standard output in constant space:

>>> Pipes.runListT echo
Test<Enter>
Test
ABC<Enter>
ABC
42<Enter>
42
<Ctrl-D>
>>>

The exception is the transformers library, whose ListT implementation does not stream or run in constant space.

Combinators

We can also implement lazy variations on Control.Monad combinators using this interface.

For example, we can implement a lazy variation on replicateM using just select and replicate:

replicateM' :: MonadPlus m => Int -> m a -> m a
replicateM' n m = do
m' <- select (replicate n m)
m'

-- or: replicateM' n = join . select . replicate n

We can use this lazy replicateM' to lazily echo 10 lines from standard input to standard output:

example :: (MonadTrans t, MonadPlus (t IO)) => t IO ()
example = do
str <- replicateM' 10 (lift getLine)
lift (putStrLn str)

We can also implement a lazy mapM and forM, too, except now their implementations are so trivial that they don't even deserve their own functions:

mapM' :: Monad m => (a -> m b) -> m a -> m b
mapM' = (=<<)

forM' :: MOnad m => m a -> (a -> m b) -> m a
forM' = (>>=)

example :: (MonadTrans t, MonadPlus (t IO)) => t IO ()
example = mapM' (lift . print) (replicateM' 10 (lift getLine))

Similarly, a lazy sequence just becomes join.

Conclusion

The following streaming libraries already provide their own implementation of ListT compatible with the above trick:

  • List
  • list-t
  • LogicT
  • pipes

The other streaming libraries do not currently provide a ListT implementation, but there is no reason why they couldn't! For example, conduit could implement an internal ListT type of its own and use that as an intermediate type for converting the above abstraction to the public Source type:

convert :: Monad m
=> Data.Conduit.Internal.ListT m a -> Source m a

This polymorphic API obviously does not capture all possible streaming patterns. For example, you can not implement something like take using this API. However, I suspect that a significant number of streaming components can be written using this dependency-free interface.

Edit: Twan van Laarhoven pointed out that you can sometimes use MonadIO instead of MonadTrans, which produces nicer constraints

Categories: Offsite Blogs

Ghc 7.8 binary packages for rhel 7 available/recommendation?

Haskell on Reddit - Mon, 11/24/2014 - 7:30am

I built it in 1 hour. But it seems too long for me if I only want to use ghc 7.8.3 on rhel 7. Is there pre-built version?

submitted by eccstartup
[link] [9 comments]
Categories: Incoming News

Philip Wadler: Towards Independence

Planet Haskell - Mon, 11/24/2014 - 4:51am
As an experiment, I have created a separate blog for political posts: Towards Independence.
Categories: Offsite Blogs

ekmett/ad

del.icio.us/haskell - Mon, 11/24/2014 - 3:58am
Categories: Offsite Blogs

ekmett/ad

del.icio.us/haskell - Mon, 11/24/2014 - 3:58am
Categories: Offsite Blogs