Re: [Haskell-cafe] Haskell image libraries

2009-11-08 Thread Stephan Friedrichs
On Sun, 2009-11-08 at 16:34 +0200, Max Rabkin wrote:
 To add image support to fdo-notify, I need an image type. Looking
 through Hackage, I didn't find any image library with the following
 features:
 * Load from a variety of formats (at least PNG and JPG, I'd say)
 * Efficient per-pixel access, or a way to dump the image into a
 ByteString as a bitmap (I need to serialise them into the protocol's
 bitmap format)
 Preferably, it should be possible to construct images programmatically too.

What about the imlib bindings [1]? The only problem is, that imlib
doesn't provide a functional image type (you'll end up processing the
image in the IO monad), but it works quite well (I used it for my Piet
interpreter, which required basic image processing tasks like a
labelling algorithm).

HTH - Stephan

[1] http://hackage.haskell.org/package/Imlib

-- 
Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Cabal packages - cabbages

2009-09-21 Thread Stephan Friedrichs
Jon Fairbairn wrote:
 Conor McBride co...@strictlypositive.org writes:
 
 On 20 Sep 2009, at 23:11, Jason Dusek wrote:

  Some day, we're going to need a short, catchy name for Cabal
  packages. Let's call them cabbages.
 Not that this is a good reason to change your mind, but some
 sufficiently ancient Brits may remember a televisual
 
 Speaking of ancient Brits, the Finns used to call Britain
 cabbage-land, in case that alters anyone's opinion.
 

Speaking of ambiguities:
http://en.wikipedia.org/wiki/Cabbage_%28disambiguation%29

CABG is especially interesting :)

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questions about haskell CPP macros

2009-07-13 Thread Stephan Friedrichs
Matthew Elder wrote:
 {-# LANGUAGE CPP #-}
 main = putStrLn (__FILE__ ++ : ++ show __LINE__)
 
 This outputs:
 test.hs:2
 
 Unfortunately, if your file is in a hierarchy of folders, this flat file
 name doesn't give much context. Is there a macro to find out the current
 module? IE if I had a module Foo.Bar.Car.MyModule, I would like to be
 able to output something like this on error:
 Foo.Bar.Car.MyModule:2

As mentioned by Claus, template-haskell offers a solution. But in some
cases, this is an overkill; consider using Control.Exception.assert, it
will provide module and line information without having to use CPP:

myHead :: [a] - a
myHead (x:_) = x
myHead []= assert False undefined

 
 [...]

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Questions about haskell CPP macros

2009-07-13 Thread Stephan Friedrichs
Malcolm Wallace wrote:
  {-# LANGUAGE CPP #-}
 main = putStrLn (__FILE__ ++ : ++ show __LINE__)

 This outputs:
 test.hs:2
 
 if I had a module Foo.Bar.Car.MyModule, I would like to be able to
 output something like this on error:
 Foo.Bar.Car.MyModule:2
 
 It works for me.  If you place that text in Try/Me.hs and call
 ghc -E Try/Me.hs
 you get
 Try/Me.hs:2
 
 If you just want to turn slashes into dots, and remove the suffix, that
 is a simple exercise in Haskell itself
 
 main = putStrLn (mangle __FILE__)
   where mangle ('/':cs) = '.': mangle cs
 mangle .

Careful, '/' might be '\\' on another OS, the file might end with .hsc
instead of .hs, the line numbers might not fit in the .hsc case...


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Adding an ignore function to Control.Monad

2009-07-11 Thread Stephan Friedrichs
Johan Tibell wrote:
 [...]
 
 I also think void is clearer than ignore.

So do I. Another point is, that it's familiar from other languages; a
function void f(...) doesn't return anything but may have an effect on
the environment.

Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code walking off the right edge of the screen

2009-06-25 Thread Stephan Friedrichs
Henning Thielemann wrote:
 [...]
 
 http://haskell.org/haskellwiki/Case

Maybe we (i. e. someone with a wiki account ;) ) should add Jeremy's
proposal - using let and guards - to the page (under section 2.2,
syntactic suger)? IMHO this is much clearer than case () of _.

foo =
let x | 1  1 = uh-oh
  | otherwise = all is well
in x

Regards,
Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Code walking off the right edge of the screen

2009-06-20 Thread Stephan Friedrichs
Deniz Dogan wrote:
 I (too) often find myself writing code such as this:
 
 if something
   then putStrLn howdy there!
   else if somethingElse
   then putStrLn howdy ho!
   else ...
 
 [...]
 
 So how do I make code like this prettier?

If it's a function, you can use guards:

foo :: ...
foo something somethingElse
| something - putStrLn howdy there!
| somethingElse - putStrLn howdy ho!
| otherwise - ...

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] curious about sum

2009-06-13 Thread Stephan Friedrichs
Jochem Berndsen wrote:
 Keith Sheppard wrote:
 Is there any reason that sum isn't strict? I can't think of any case
 where that is a good thing.

 Prelude sum [0 .. 100]
 *** Exception: stack overflow
 
 It is useful if the (+) is nonstrict; although I cannot think of any
 useful mathematical structure where (+) would be nonstrict.

What about some numeric representations?

type MyNum = [()]

instance Num MyNum where
  (+) = (++)

Regards,
Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad transformer responsibilities

2009-06-08 Thread Stephan Friedrichs
Henning Thielemann wrote:
 [...]
 
  - So you have to declare them near the test cases and they're orphan
instances

 The entire project doesn't issue a single warning when compiling with
 -Wall *except* two orphan instances when building the test cases...
 
 However, I had sometimes the case, where a type from another library was
 part of my tests and thus I needed its Arbitrary instance. I could have
 defined instances for the foreign types, but they would have been orphan
 and I risk that the library author decides to add the instances later.
 

Hmm... maybe it is a good idea to aktivate the instance declaration with
a cabal flag? I've already got:

Flag Test
  Description:   Build a binary running test cases
  Default:   False

and I could easily add something like

if flag( Test )
  CPP-Options:   -D__TEST__
  Build-Depends: QuickCheck = 2   3

and

data MyType = ...

#ifdef __TEST__
instance Arbitrary MyType where
...
#endif

A usage of cabal flags that strongly reminds me of Gentoo's useflags :)
However, this will result in a total mess with more than one such flag...

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad transformer responsibilities

2009-06-05 Thread Stephan Friedrichs
Hi,

it's alomost the same problem when you're writing a library with
optional quickcheck test cases: Where to put the Arbitrary instances?

 - You can't put them into quickcheck
 - You don't want to put them in the library (because of the quickcheck
   dependency)
 - So you have to declare them near the test cases and they're orphan
   instances

The entire project doesn't issue a single warning when compiling with
-Wall *except* two orphan instances when building the test cases...

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: heap-1.0.0

2009-06-03 Thread Stephan Friedrichs
Hello haskell-cafe,

I'm pleased to announce a rewrite of the heap package, heap-1.0.0 [1].
It is not 100% compatible to the version 0.6.0, but provides major
improvements:

 - The HeapPolicy type class hack used to distinguish between min- max-,
   min-prio- and max-prio-heaps has been replaced by the HeapItem type
   family (the type family provides functions to convert insertable
   'items' to (priority, value) pairs and back. Thus a static min-heap
   (HeapT) can be used as underlying implementation, but the package can
   still provide MinHeap, MaxHeap, MinPrioHeap and MaxPrioHeap.

 - A nice side effect of the above is, that ({Min,Max}PrioHeap p) now
   is an instance of Functor

 - Faster {from,to}{Asc,Desc}List conversions

 - A binary with quickcheck test cases can now be built from cabal (with
   a Test flag) (the old versions already had lots of test cases, but
   cabal didn't know about them).

Regards,
Stephan

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/heap-1.0.0

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-09 Thread Stephan Friedrichs
Neil Mitchell wrote:
 
 [...]
 
 Which is a shame, having Bits on Bool seems entirely logical, having
 Num a superclass of Bits seems a little less clear.
 

There are two default implementations in Bits

bit i = 1 `shiftL` i
x `testBit` i = (x .. bit i) /= 0

which rely on Num (and on the fact that 0 ~= 0..0 and 1 ~= 0..01, which
doesn't have to be the case in all Num instances?). But is that worth
having Num as superclass? When declaring in instance for Bits you have
to implement at least 8 functions anyway so these two IMHO don't really
make a difference, do they?

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Stephan Friedrichs
Hi!

When looking for an xor function, I found one in Data.Bits but couldn't
use it for Bool, because Bool is no instance of Bits and of Num (which
would be necessary, because it's class (Num b) = Bits b). My question
is: Why not?

We could declare

instance Num Bool where
(+) False = id
(+) True  = not

(*) True  True = True
(*) _ _= False

(-) = (+)

negate  = id
abs = id
signum  = const True
fromInteger = not . even

which basically implements the field with 2 elements and

instance Bits Bool where
bitSize  = const 1
isSigned = const False

(..) = ()
(.|.) = (||)
xor   = (+)

complement = not

shift  = const
shiftL = const
shiftR = const

rotate  = const
rotateL = const
rotateR = const

bit = (==0)

setBit _ 0 = True
setBit b _ = b

clearBit _ 0 = False
clearBit b _ = b

complementBit b 0 = not b
complementBit b _ = b

testBit b 0 = b
testBit _ _ = False

quite trivial... Why is this not part of base? Or am I missing something?

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Stephan Friedrichs
Deniz Dogan wrote:
 instance Num Bool where
(+) False = id
(+) True  = not

(*) True  True = True
(*) _ _= False

 
 Isn't XOR for booleans (/=)?

Oh right. And (*) would be ():

instance Num Bool where
(+) = (/=)
(*) = ()
-- ...

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Trouble with type signatures and type families

2009-04-22 Thread Stephan Friedrichs
Hi,

consider the following code:


class Foo f where
type Bar f :: *
type Baz f :: *

from :: Bar f - Baz f
to   :: Baz f - Bar f

data Tree a b c
= Empty
| Tree b c (Tree a b c) (Tree a b c)

--singleton :: (Foo f) = Bar f - Tree a (Bar f) (Baz f)
singleton x = Tree x (from x) Empty Empty


what type does 'singleton' have? ghci-6.10.2 says:

 :t singleton
singleton :: forall f a. (Foo f) = Bar f - Tree a (Bar f) (Baz f)

which is no surprise. But when I uncomment the type signature in the
above code sample, loading it to ghci gives the following error:

 :r
[1 of 1] Compiling Main ( T.hs, interpreted )

T.hs:14:22:
Couldn't match expected type `Baz f1' against inferred type `Baz f'
In the second argument of `Tree', namely `(from x)'
In the expression: Tree x (from x) Empty Empty
In the definition of `singleton':
singleton x = Tree x (from x) Empty Empty

T.hs:14:27:
Couldn't match expected type `Bar f' against inferred type `Bar f1'
In the first argument of `from', namely `x'
In the second argument of `Tree', namely `(from x)'
In the expression: Tree x (from x) Empty Empty
Failed, modules loaded: none.

I don't get it... what's wrong, I just copied the inferred type?

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Trouble with type signatures and type families

2009-04-22 Thread Stephan Friedrichs
Gleb Alexeyev wrote:
 You may want to read the comments at
 http://hackage.haskell.org/trac/ghc/ticket/1897.

Wow that's subtle... Thanks a lot!

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad transformer to consume a list

2009-04-07 Thread Stephan Friedrichs
Henning Thielemann wrote:

 is there a monad transformer to consume an input list? I've got external
 events streaming into the monad that are consumed on demand and I'm
 not sure if there's something better than a StateT.
 
 I wondered that, too. I wondered whether there is something inverse to
 Writer, and Reader is appearently not the answer. Now I think, that
 State is indeed the way to go to consume a list. Even better is StateT
 List Maybe:
 
 next :: StateT [a] Maybe a
 next = StateT Data.List.HT.viewL   -- see utility-ht package
 

But a StateT provides the power to modify the list in other ways than
reading the first element (modify (x:)). Maybe ParsecT is closer to what
I'm looking for ;)

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monad transformer to consume a list

2009-04-07 Thread Stephan Friedrichs
My solution is this transformer:



newtype ConsumerT c m a
= ConsumerT { runConsumerT :: [c] - m (a, [c]) }

instance (Monad m) = Monad (ConsumerT c m) where
return x = ConsumerT $ \cs - return (x, cs)
m = f  = ConsumerT $ \cs - do
 ~(x, cs') - runConsumerT m cs
 runConsumerT (f x) cs'
fail msg = ConsumerT $ const (fail msg)

consume :: (Monad m) = ConsumerT c m (Maybe c)
consume = ConsumerT $ \css - case css of
   [] - return (Nothing, [])
   (c:cs) - return (Just c, cs)

consumeAll :: (Monad m) = ConsumerT c m [c]
consumeAll = ConsumerT $ \cs - return (cs, [])


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Monad transformer to consume a list

2009-04-06 Thread Stephan Friedrichs
Hello,

is there a monad transformer to consume an input list? I've got external
events streaming into the monad that are consumed on demand and I'm
not sure if there's something better than a StateT.

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Optional EOF in Parsec.

2009-04-04 Thread Stephan Friedrichs
Kannan Goundan wrote:
 I'm writing a parser with Parsec.  In the input language, elements of a 
 sequence
 are separated by commas:
 
[1, 2, 3]
 
 However, instead of a comma, you can also use an EOL:
 
   [1, 2
   3]
 
 Anywhere else, EOL is considered ignorable whitespace.  So it's not as simple 
 as
 just making EOL a token and looking for (comma | eol).

Hi Kannan,

let's construct the parser top-down. On the top level, you have opening
and closing characters, '[' and ']'. Parsec has a function for that:

 between (char '[') (char '])

And what's in between? A list of elements separated by something. Parsec
provides a sepBy function for that:

 element `sepBy` separator

which parses a list of elements separated by separator. What's your
separator? Well it's either ',' or a new line and spaces before and
after that:

 mySpaces  (newline | char ',')  mySpaces -- [1]

Let's combine what we've got:

myListOf :: (Parsec String () a) - Parsec String () [a]
myListOf elem = between
(char '[')
(char ']')
(elem `sepBy` (mySpaces  (newline | char ',')  mySpaces))
where
mySpaces = many (oneOf ( \t))

And test it in ghci:

*Main parseTest (myListOf anyChar) [a , b, d ,d\np]
abddp

Hope this helps!

 Stephan

PS: The important thing is that there are a lot solutions for tricky
situations (like yours) in Text.Parsec.Combinator (especially the sepBy
and many families). Knowing them can save a lot of work :)

[1] I don't use parsec's spaces function because it also accepts newline
characters.

 
 I've implemented this functionality in a hand-written parser (basically a hack
 that keeps track of whether the last read token was preceded by an EOL,
 without making EOL itself a token).  Does anybody have ideas about how to
 do this with Parsec?
 
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 



-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Stephan Friedrichs
Hi,

when I tried to reorganize some code to use the data-accessor and
data-accessor-template packages, i stumbled across a strange effect:
When using template haskell some things are out of scope that really
shouldn't be. Let me give an example:



== T.hs ==
{-# LANGUAGE TemplateHaskell #-}

data Foo = Foo
{ bar :: Bar
}

$( return [] )

data Bar = Bar
==

 ghci T.hs
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( T.hs, interpreted )

T.hs:4:13: Not in scope: type constructor or class `Bar'
Failed, modules loaded: none.




No matter what you do in $( ... ), the code doesn't compile. Even in the
simple case above, it doesn't work. What's happening here? Bug or
feature? And do you know a workaround?

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Template Haskell messes up scoping?

2009-03-29 Thread Stephan Friedrichs
Hi Martijn,

Martijn van Steenbergen wrote:
 [...]
 
 Apart from the specific problematic file you gave, I had some other
 scoping issues when using TH to generate the accessors. I worked around
 this by defining my data types in a separate module Types and calling
 the TH functions in that module as the last lines. [...]
 

looks like your workaround also works in this case. This file (the
template instanciation was moved to the last line) compiles:

== T.hs ==
{-# LANGUAGE TemplateHaskell #-}

data Foo = Foo
{ bar :: Bar
}

data Bar = Bar

$( return [] )
==

It looks like the scope is interrupted just above $( ... ) - but I'd
like to know why and find a more beautiful way than just moving all th
calls to the bottom of the module file :)

Regards
 Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] View patterns and warnings about overlapping or non-exhaustive patterns

2009-03-11 Thread Stephan Friedrichs
Hi,

I'm working on a data structure that uses Data.Sequence a lot, so views
are important and I tried to simplify my code using view patterns.

The problem is, that I keep getting warnings about both overlapping and
non-exhaustive pattern matches. A simple test case:

===T.hs===
{-# LANGUAGE ViewPatterns #-}

import Data.Sequence

test :: Seq a - Seq b - String
test (viewl - EmptyL) (viewl - EmptyL) = empty, empty
test (viewl - EmptyL) (viewl - _ : _) = empty, non-empty
test (viewl - _ : _) (viewl - EmptyL) = non-empty, empty
test _ _ = non-empty, non-empty
==

 ghci -Wall T.hs
GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( T.hs, interpreted )

T.hs:6:0:
Warning: Pattern match(es) are overlapped
 In the definition of `test':
 test ((viewl - EmptyL)) ((viewl - EmptyL)) = ...
 test ((viewl - EmptyL)) ((viewl - _ : _)) = ...
 test ((viewl - _ : _)) ((viewl - EmptyL)) = ...
 test _ _ = ...

T.hs:6:0:
Warning: Pattern match(es) are non-exhaustive
 In the definition of `test': Patterns not matched:
Ok, modules loaded: Main.

*Main test empty (singleton 'a')
empty, non-empty
*Main test (singleton 'b') (singleton 'a')
non-empty, non-empty
*Main test (singleton 'b') empty
non-empty, empty
*Main test empty empty
empty, empty

There are warnings about non-exhaustive and overlapping pattern matches,
but the tests show that this isn't the case. So what's the problem? I
don't want to turn off or ignore warnings.

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] View patterns and warnings about overlapping or non-exhaustive patterns

2009-03-11 Thread Stephan Friedrichs
Svein Ove Aas wrote:
 [...]
 
 For the time being, it will *work*, you just won't get useful
 warnings. Hopefully it's going to be fixed for 10.2.
 

Hmm I don't find #2395 anywhere on
http://hackage.haskell.org/trac/ghc/milestone/6.10.2 :(

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] question on types

2009-02-18 Thread Stephan Friedrichs
Daryoush Mehrtash wrote:
 Is there a way to define a type with qualification on top of existing
 type (e.g.  prime numbers)?   Say for example I want to define a
 computation that takes a prime number and generates a string.   Is there
 any way I can do that in Haskell?

Haskell's type system is decidable, so you can't let the type system
check arbitrary properties. It probably is possible in C++ by some
template hack (C++ templates are Turing complete), but not in Haskell.
But, as mentioned in the other responses, you can

 - use a representation that makes it impossible to use wrong values
   (- Ketil's n-th prime representation)

 - check values at runtime (- Luke's repsonse)

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] UDP

2009-01-31 Thread Stephan Friedrichs
Andrew Coppin wrote:
 I'm trying to write a simple program that involves UDP. I was hoping
 something like this would work:
 
 [...]

How about using bindSocket? At least that's the main difference between
your code snippet and our (UDP-using) barracuda project :)

 
 main2 = do
  s - socket AF_INET Datagram defaultProtocol
  bindSocket s ...
  putStrLn Waiting...
  x - recv s 100
  putStrLn x
 
 [...]
 

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haddock bug for strict unpacked fields?

2009-01-21 Thread Stephan Friedrichs
Hi,

using haddock-2.4.1 and this file:

 module Test where

 data Test
 = NonStrict Int
 | Strict !Int
 | UnpackedStrict {-# UNPACK #-} !Int

The generated documentation looks like this:

data Test
Constructors
  NonStrict Int
  Strict !Int
  UnpackedStrict !!Int

Note the double '!' in the last constructor. This is not intended
behaviour, is it?

//Stephan


-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Stupid question #852: Strict monad

2009-01-01 Thread Stephan Friedrichs
Hello Brian,

Brian Hurt wrote:
 
 [...]
 
 So today's question is: why isn't there a Strict monad?  Something like:
 
 data Strict a = X a
 
 instance Monad Strict where
 ( = ) (X m) f = let x = f m in x `seq` (X x)
 return a = a `seq` (X a)

unless I am mistaken, this violates the first monad law (see Prelude
documentation)

  return a = k  ==  k a

for k = const (return 3) and a = undefined, because

  return undefined = _  === _|_

but

  const (return 3) undefined === return 3

Generally speaking, the first monad law only holds for strict functions
in your monad.

 
 [...]
 

Happy new year,
Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] followedBy parser in Parsec

2008-11-27 Thread Stephan Friedrichs
Paul Keir wrote:
 Is there a way in Parsec to check what the next token is, and if it is
 what you're hoping for, leave it there.

Maybe you're looking for 'lookAhead'?

 
 [...]

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: cabal install HaXml installs wrong version unless I specify the version number

2008-11-16 Thread Stephan Friedrichs
Don Stewart wrote:
 [...]
 
 Note that packages that depend on the 'experimental' versions of things
 (in particular Haxml 1.19.* can't be packaged for Arch either, as we can
 only install one version of the haskell-haxml package).

In this case we definetely need haxml-1.19. IIRC we even committed
patches to the haxml repository, when we were developing Barracuda a
year ago :)

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: cabal install HaXml installs wrong version unless I specify the version number

2008-11-15 Thread Stephan Friedrichs
Thomas Hartman wrote:
 When I specify
 
 Build-Depends:  base, parsec, HaXml = 1.19.4
 
 in xml-parsec.cabal
 
 it does install correctly.

I just fixed xml-parsec.cabal and uploaded it on hackage:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/xml-parsec-1.0.3

 
 [...]
 

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Hackage Build Failures

2008-10-01 Thread Stephan Friedrichs

Emil Axelsson wrote:

[...]

The error comes from using QuickCheck 2, which happens to also use the 
operator (). I can see two ways to solve the problem:


(1) Add  2 after QuickCheck in the Wired.cabal file.

(2) Add hiding (()) after import Test.QuickCheck in 
Data/Hardware/Internal.hs


Emil,

my suggestion is: Please use alternative (2), at least if there are no 
further problems with quickcheck 2! Otherwise, depending on quickcheck 
2 just introduces unnecessary package incompatibilities.




[...]



//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Red-Blue Stack

2008-09-26 Thread Stephan Friedrichs
apfelmus wrote:
 [..]
 
 Persistent data structures are harder to come up with than ephemeral
 ones, [...]

Yes, in some cases it's quite hard to find a persistent solution for a
data structure that is rather trivial compared to its ephemeral
counterpart. My question is: Is there a case, where finding a persistent
solution that performs equally well is *impossible* rather than just
harder? I mean might there be a case where (forced) persistence (as we
have in pure Haskell) is a definite disadvantage in terms of big-O
notation? Do some problems even move from P to NP in a persistent setting?

Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Line noise

2008-09-22 Thread Stephan Friedrichs
Andrew Coppin wrote:
 [...]
 - Variable names such as x and f aren't fabulously helpful to lost
 programmers trying to find their way.

I'm not a fan of cryptic variable names, either, and I try to use
descriptive names wherever I can. But in Haskell...

 - ... you often have variables, which have a scope of far less than a
   line such as in map (\(x, (_, y)) - (x, y) ... (cleaning
   intermediate results from a list).

 - ... things often get very abstract, so that it just feels wrong
   matching on, say, (socket:sockets) instead of (x:xs).

 
 [...]
 

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Views

2008-09-14 Thread Stephan Friedrichs
Johannes Waldmann wrote:
 a) ... to use Maybe
 b) ... to provide my own Data.Heap.View type
 
 leave the choice up to the programmer,
 and provide a generic interface,
 accepting any MonadZero (*) instance.
 
 cf. Data.Set.maxView

AFAIK there has been a vivid discussion about that. I think the crux of
the matter was that a monad is too general. Either there is a result or
there is not. That's precisely the intended use of a Maybe.

Besides, I just learned that Data.Map.{lookup,minView,maxView} and the
like have been modified to return a Maybe in the current GHC head
branch, see [1]. This suggests using Maybe in my case as well.

 
 [...]
 

[1]
http://www.haskell.org/ghc/dist/current/docs/libraries/containers/Data-Map.html

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Views

2008-09-14 Thread Stephan Friedrichs
Johannes Waldmann wrote:
 I think the crux of
 the matter was that a monad is too general. Either there is a result or
 there is not. That's precisely the intended use of a Maybe.
 
 Indeed Monad m = is dangerous here
 because not every Monad has a reasonable definition of fail.
 
 But that seems to be a problem in the (current) definition of Monad,
 and its solution was MonadZero, no?

I agree that the MonadZero class with a useful 'zero' :: m a would be
the right abstraction for views. But MonadZero is not part of base, mtl
or any other common package, or am I missing something? Changing this is
beyond a simple heap package ;)

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Views

2008-09-13 Thread Stephan Friedrichs
Hello!

List-like data structures should IMHO provide safe versions of 'head'
and 'tail' (with safe I mean 'not partial', i. e. functions that don't
provoke an 'error' when called with an empty collection). As far as I
know, this is usually called 'view' and and has a type signature like

view :: SomeDataStructure a - View a

with

data View
  = Empty
  | Cons a (SomeDataStructure a)

A good example for this is Data.Sequence. My question is: Why is this
not expressed in terms of Maybe?

view :: SomeDataStructure a - Maybe (a, SomeDataStructure a)

This would be easier to use, as there's no need for a new View type and
because Maybe already provides instance declarations for a lot of useful
classes (Functor, Monad, etc.) and handy helper functions (e. g.
'maybe'). Then you could, for instance, say:

head xs = maybe undefined fst (view xs)
tail xs = maybe undefined snd (view xs)

You can of course argue that you want viewl and viewr to have different
types in the case of Data.Sequence, but this is not the case for other,
rather one-ended, data types, is it?

Long story short, my problem is the following: I want to provide a
'view' function for Data.Heap in my heap [1] package and I don't know
whether...

a) ... to use Maybe
b) ... to provide my own Data.Heap.View type
c) ... a Data.View package with a View type should be included in
   the containers- or even base-package. This would prevent lots of
   small projects from creating totally equivalent View types.

Maybe there even exists a Data.View package that I didn't find?

Regards,
Stephan

[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/heap-0.3.1

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] language proposal: ad-hoc overloading

2008-08-31 Thread Stephan Friedrichs
Miguel Mitrofanov wrote:
 Suppose you have different thing all named insertWith. You've got one
 somewhere in your program; how do YOU know when looking at the code
 after a month or so, which one is this?

We already have that situation when classes are involved. If you replace
specialised functions by abstractions provided classes, for instance

mempty   instead of Data.Structure.empty
fmap instead of Data.Structure.map
folds from Data.Foldable instead of a specialised module

There certainly are more examples, but these are the most common.

IMHO this doesn't make code much harder to read. mempty gives us some
empty data structre, fmap applies a function to all its elements and
folds do the same. It doesn't matter if we're talking about lists, sets
or something else.

And it has the huge advantage that you can replace a data structure by
another (Maybe by [], [] by Set, ...) simply by changing a type
signature and not the code.

 Certainly, given a smart IDE you
 can ask it; but I think that code should be clear just when you look at
 it, without any action.

I think that - at least in the examples listed above - the code remains
very clear.

 
 [...]
 

Regards,
Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Pure hashtable library

2008-08-27 Thread Stephan Friedrichs
Bulat Ziganshin wrote:
 solving one more task that uses English dictionary, i've thought: why we
 don't yet have pure hashtable library? There is imperative hashtables,
 [...]
 how should it look:
 
 * hashtable is represented as an array of assoc lists: Array Int [(a,b)]

Don't immutable arrays get rather inefficient when modified?

 
 [...]

Just a tought: You might want to have a look at the bloom filter
implementation. On one hand, it is an alternative for your dictionary
and on the other and, its implementation uses hash functions and arrays
as well. IIRC it does that in a state monad that keeps the array mutable
and finally freezes it before usage, which might be a good idea for pure
hash table as well.

//Stephan

-- 

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANN: random-access-list-0.1

2008-06-13 Thread Stephan Friedrichs

Isaac Dupree wrote:

[...]


Well Chris Okasaki called them Skew Binary Random-Access Lists, 
which is even longer :)


:)

hmm.. IndexableList? (just a thought, not sure whether I like it any 
better)


RAList?
IList? - (will I be sued by a large computer company for that?)


[...]
Yes, I wasn't happy with that one either. The view-concept of 
Data.Sequence is a good idea.


 yeah, it's a good idea, although I'm not sure how much I like the
 particular syntax of how it's done in Data.Sequence (the view-types'
 constructor names, mostly)

I now have

data View a
= Empty
| Cons a (RandomAccessList a)

and

view :: RandomAccessList a - a

additionally, I renamed extractHead to uncons (which is OK, because 
I also have cons) but still left head and tail with the typical 
list-like behaviour (causing an error on empty lists).



[Monad vs. Maybe]


That's quite convincing, most of all that fail has rather strange 
definitions for many Monads (because it originally does not belong to 
monads, does it?).



[...]


The size function is in O(1) because I cache it, otherwise it would be

size (RandomAccessList xs) = sum (map fst xs)

which is O(log n). I consider the caching useful, as most applications 
will check 0 = i  size quite often.


sounds good

[...]

If two lists have exactly the same size, all the complete binary trees 
holding the data have the same size as well. This can be zipped 
directly and is a bit (~5% in my tests) faster.


okay, that sounds like a fair optimization, since zipping same-size 
lists is a nice thing to do anyway.  But the asymptotic speed ideally 
should still be O(min(m,n)), if possible?


Well... I guess that's possible converting the shorter one into a list 
and using fold for zipping. I'll have a close look at this!



--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANN: random-access-list-0.1

2008-06-12 Thread Stephan Friedrichs

Isaac Dupree wrote:
 [...]

 Great to see it, it deserved implementing, IIRC!  I don't remember 
enough about it.. (and don't have Okasaki anywhere handy). Can it be 
lazy or infinitely long?


No, it has to be finite as it's actually a list of complete binary trees 
whose size depend on the skew binary representation of the list's size. 
I'll document this.


 [...]

 Is RandomAccessList the best name for something that's not O(1), 
just O(log n)?  Or just that RandomAccessList is just much longer than 
[]?


Well Chris Okasaki called them Skew Binary Random-Access Lists, which 
is even longer :)



 don't use those unorthodox infix function names.. `cons` is hardly 
worse than .:. , `append` or `mappend` than .+. , and .!. than, hmm.. . 
Export a ++ and ! (!! ?) if you're really dedicated. But I'd prefer an 
`at` that's the same partial indexing operation, rather than the name 
.!. (I think this at was a new name being put somewhere else? partly 
because ! is trying to be gradually used only to refer to strictness?)


Good point!


 extractHead is an ugly name for a nevertheless standardish-meaning 
function... what is it usually called? uncons? headTail? (Data.Sequence, 
which is meant to be left-right symmetric, calls it viewr... except 
your version doesn't have the Maybe, it's partial instead, fails on 
empty lists)


Yes, I wasn't happy with that one either. The view-concept of 
Data.Sequence is a good idea.



 For index, don't use Monad, use Maybe (I think that's what the 
recent [EMAIL PROTECTED] discussion concluded, in the context of 
switching Data.Map back to Maybe).


I was just copying the idea from Data.Map and it's usually a good thing 
to have functions as general as possible, or why is it not?


 Also, Data.List has genericLength etc, to

At the moment, I'm using the Int type for size and indexing only for one 
reason: I haven't found a proper way to generalize it. I'd really like 
to use the Ix class, but it doesn't provide enough functionality, it 
only works on fixed-size intervals (i. e. for arrays, which don't change 
their size, but a list does). Maybe someone has an idea of how to 
realize lists with a variable starting index and size?


 support.  Isn't index (like Data.List.genericIndex) supposed to be 
a name for a partial operation, not one that returns a Maybe?  Shouldn't 
size be named length (or exported as both names, since e.g. 
Data.Map.size, .List.length) (why is it O(1) not O(log n)? Is it 
possible for these RandomAccessLists to be longer than maxBound::Int?)?


The size function is in O(1) because I cache it, otherwise it would be

size (RandomAccessList xs) = sum (map fst xs)

which is O(log n). I consider the caching useful, as most applications 
will check 0 = i  size quite often.



 for e.g. toList, is the O(n) cost spread over traversing/demanding 
the items of the generated list, or all up-front, or somewhere in between?


 Why is zip slow with unbalanced lists?  Obviously, it could be 
implemented O(min(m,n)*(log m + log n)) just indexing each one, which 
would be faster for really unbalanced-size lists...  Obviously, I don't


If two lists have exactly the same size, all the complete binary trees 
holding the data have the same size as well. This can be zipped directly 
and is a bit (~5% in my tests) faster.


 understand the implementation.  BTW, looking at the file,
 data RandomAccessList a
 = RandomAccessList {-# UNPACK #-} !Int ![(Int, CBTree a)]
 Marking a list strict like that doesn't have much effect because it 
only makes the first (:) or [] strict. Did you mean for an 
element-strict or spine-strict(which would necessarily be non-infinite) 
list?


Oh, you're right, I just meant to mark the Int strict. It obviously was 
too late yesterday!


Thanks for this feedback!
//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: random-access-list-0.1

2008-06-12 Thread Stephan Friedrichs

Chris Smith wrote:

Chaddaï Fouché wrote:

Given that this structure isn't lazy enough, I really don't see a
problem with using Int (any random access list with a size that needs an
Integer would blow the memory anyway...).


Bad way to think about things.  The implications of using Int as the 
result type of a function extend far beyond just storing the result 
type.  They also include doing other computations that depend on the 
result type, and with enough type inference, the broken Int type 
propogates throughout the program.




I'd like not to be restricted to Int, but what's the proper way to do 
so? Just adding genericFun = fromInteger . toInteger . fun functions 
is just as bad as using Ints directly. What I need is something like a 
more general Ix class that is not limited to a fixed interval:


class Ix2 i where
-- convert starting index and given index to an Int for internal
-- representation
toIndex   :: i - i - Int

-- given an internal Int index and a starting index, return the
-- representing index
fromIndex :: Int - i - i

-- translate a starting index and a number of elements into a
-- size
size  :: i - Int - i

This is meant to work with a starting-index and a given index, so that a 
list does not have to start at index 0. Is there something like this? Or 
is it somehow possible to use the existing Ix class to do that?


//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] question about STM and IO

2008-02-12 Thread Stephan Friedrichs

Hello,

John Lato wrote:

I was recently looking at the STM library, and I have a question about
the function unsafeIOToSTM.  Can anyone explain to me what is unsafe
about it, and what sort of use would be considered safe?


it's unsafe to perform IO inside of a transaction as it can't be undone, 
when rolling it back. I guess, unsafeIOToSTM has been designed in order 
to allow us to inject debugging output into a transaction, but you 
really shouldn't use it to perform real IO (like writing files, etc.).


HTH - Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANN: heap-0.2

2008-02-04 Thread Stephan Friedrichs
A flexible heap implementation supporting min-, max- and custom-ordered 
heaps.


New features since version 0.1:
 - Foldable and Read instance
 - filter, partition
 - subrange functions: take, drop, splitAt, takeWhile, span, break

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/heap-0.2.1

//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Data.Ord and Heaps (Was: Why functional programming matters)

2008-02-04 Thread Stephan Friedrichs

Hi,

I'm sorry it took me so long to respond!

[EMAIL PROTECTED] wrote:

[newtype Ord a = Reverse a = Reverse { unReverse :: a }]

This solution should be used for all collections depending on Ord 
instances, including Data.Map, Data.Set and others. As long as I only 
include it in my tiny heap package, it is as 'non-standard' as my 
approach, isn't it?


Yes. I mean non-standard in the software-reuse sense, i.e. Ord is for 
user-defined orderings and should be the only such mechanism in order to 
enable reuse. In fact, Data.Heap clearly shows that Data.Ord is 
currently missing functionality.


Ah, now I see. The entire ordering policy mechanism - no matter how it 
is going to be solved - belongs into Data.Ord and not in Data.Heap. As 
soon as Data.Ord provides a solution, I'll use it in Data.Heap.




[...]

Note that the Heap class contains only three primitive operations 
(empty, insert, viewHead), all the others have default implementations 
in terms of those three. There is even an underappreciated unfold among 
them :)


  toAscList = unfoldr viewHead

The structure becomes especially clear by noting that any Heap is 
defined by just two primitives


  inject :: Ord a = Maybe (a, Heap a) - Heap a
  view   :: Ord a = Heap a - Maybe (a, Heap a)

We have  inject = maybe empty (uncurry insert)  . This is just like 
lists, except that  view . inject ≠ id   since  view  returns the 
smallest element.


I stumbled over the similarity of heaps and lists when implementing 
take, takeWhile, span, break, etc. (btw, they are included in heap-0.2 
which I uploaded yesterday); so a heap is really nothing but a packed 
representation of a sorted list :)




However, just that we managed to reduce the number of primitive 
operations doesn't mean that the policy approach isn't preferable. It 
needs 0 primitive operations, after all. But as foreshadowed in my 
reply, it's possible to do policies within Ord. Don't stop thinking 
about your good idea just because you can start coding :)


Here's one way to do it:

   [...]

In conclusion: the ordering policy stuff should not be part of 
Data.Heap, this is a job for Data.Ord.
As mentioned above: This sounds really useful. How about you propose 
this to the base-package maintainers? :)


What, me? :D


Where? :)

Regards, Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] NDP

2008-01-30 Thread Stephan Friedrichs

Roman Leshchinskiy wrote:

[...]

Yes, me :-) Sorry for the late reply, it's been a long weekend here in 
Australia.


Wow, Australia :)



[...]

I suspect that cd examples; make doesn't quite work at the moment 
because some of the examples are broken. I'll try to fix that soon. But 
cd examples/dotp; make should work.


Hmm I must have missed that the ndp package didn't quite compile. Right 
now, I'm darcs pulling everything (ghc, libraries, ndp) and rebuilding it...


... and ghc failed. Looks like I have to wait for some patches.



(.text+0x8d5): undefined reference to 
`__stginit_parallelzm1zi0zi0zi0_ControlziParallelziStrategies_'


This is strange, I've never seen this. Can you please send me the exact 
commands you used to build ghc and package ndp and the complete log from 
making dotp?


As far as I can remember:

# in the ghc directory:
darcs pull -a
./darcs-all pull -a
sh boot
./configure
make -j5
cd libraries
darcs get --partial http://url/of/ndp/package/
make make.library.ndp

I'm currently stuck at 'make -j5'. As soon as it works, I'll give you 
precise feedback.




Roman



Thank you!

//Stephan

PS: Is 'make clean' in the ghc directory enough for a complete rebuild?

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] NDP

2008-01-30 Thread Stephan Friedrichs

Roman Leshchinskiy wrote:

[...]

You should make clean in ndp/examples. Sorry this doesn't happen 
automatically, the whole setup is a bit of a mess at the moment.


Now it works, thanks a lot :)




Sorry for the German make output, but I'm no admin on this machine


No worries, I actually speak German :-)


:D



Roman



//Stephan

PS: ndp is a great technology, I can't wait to see it going stable :)

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] Why functional programming matters

2008-01-30 Thread Stephan Friedrichs

Don Stewart wrote:

stephan.friedrichs:

[...]

We [1] implemented an ad-hoc chat system in Haskell in the SEP [2] at 
the TU-Braunschweig.


Wow!

Looks like lots of great code in there,

http://sep07.mroot.net/documentation/barracuda/

Text.ParserCombinators.Parsec.XML
Codec.Encryption.PKCS1
Network.GnuTLS
Data.Heap

Will we see this packaged for hackage.haskell.org soon?
Some of those modules look very reusable.


I just uploaded a generalised heap (min-, max- and custom-heaps) 
implementation:


http://hackage.haskell.org/cgi-bin/hackage-scripts/package/heap-0.1

Feedback would be appreciated :)

//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Crash in Data.ByteString.Lazy.hPut

2008-01-28 Thread Stephan Friedrichs

Brandon S. Allbery KF8NH wrote:


On Jan 28, 2008, at 17:33 , Jamie Love wrote:

Shouldn't haskell pick up that there is no 'mod' for Word8?  I mean, 
shouldn't I get a nicer error message?


Hm?  mod works fine for Word8, unless you specify a multiple of the 
type's bound.  I think it's still hard for compilers to catch that for 
you 


Finding out if a variable will have a value of 0 is undecidable at 
compile time, isn't it?


//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] NDP

2008-01-25 Thread Stephan Friedrichs

Hi all,

is someone familiar with compiling ndp (nested data parallel Haskell), 
Speed with less convenience-version?


I followed the guide at 
http://www.haskell.org/haskellwiki/Data_Parallel_Haskell/PackageNDP but 
executing make in the examples directory issues the following error:


(.text+0x8d5): undefined reference to 
`__stginit_parallelzm1zi0zi0zi0_ControlziParallelziStrategies_'


manually compiling the dotp example on the link mentioned above doesn't 
work either:


[...]

(.data+0x5c): undefined reference to 
`ndp_DataziArrayziParallelziUnliftedziFlatziUArr_zdf14_closure'

DotP.o: In function `sz3_srt':
(.data+0x88): undefined reference to 
`ndp_DataziArrayziParallelziUnliftedziFlatziBasics_toU_closure'

DotP.o: In function `sz3_srt':
(.data+0x8c): undefined reference to 
`ndp_DataziArrayziParallelziUnliftedziFlatziUArr_zdf14_closure'

/home/sfriedrichs/ghc/rts/libHSrts.a(Main.o): In function `real_main':
Main.c:(.text+0x12): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x2c): undefined reference to `ZCMain_main_closure'

Does someone know, what's wrong? I'm using ghc-6.9.20080124 as source 
base (which compiled and works just fine).


//Stephan

--

Früher hieß es ja: Ich denke, also bin ich.
Heute weiß man: Es geht auch so.

 - Dieter Nuhr



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe