Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. DPH help (Luca Ciciriello)
2. Re: DPH help (Jasper Lievisse Adriaanse)
3. Functional Dependencies (dan portin)
4. Disjunction (Russ Abbott)
5. Re: Disjunction (Antoine Latter)
6. Re: Disjunction (Antoine Latter)
7. Re: Disjunction (Edward Z. Yang)
8. Re: Disjunction (Tony Morris)
----------------------------------------------------------------------
Message: 1
Date: Thu, 9 Dec 2010 17:52:09 +0100
From: Luca Ciciriello <[email protected]>
Subject: [Haskell-beginners] DPH help
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi All.
I'm trying to load in GHCi the following code:
{-# LANGUAGE Arrows #-}
{-# LANGUAGE PArr, ParallelListComp #-}
module Test where
import Control.Arrow
import Control.Parallel
dotp :: Num a => [:a:] -> [:a:] -> a
dotp xs ys = sumP [:x * y | x <- xs | y <- ys:]
......
Then I get the error:
Not in scope 'sumP'.
What I have to import to avoid this error? Where is defined sumP?
Thanks in advance for any answer.
Luca
------------------------------
Message: 2
Date: Thu, 9 Dec 2010 18:18:31 +0100
From: Jasper Lievisse Adriaanse <[email protected]>
Subject: Re: [Haskell-beginners] DPH help
To: Luca Ciciriello <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Thu, Dec 09, 2010 at 05:52:09PM +0100, Luca Ciciriello wrote:
> Hi All.
>
> I'm trying to load in GHCi the following code:
>
>
> {-# LANGUAGE Arrows #-}
> {-# LANGUAGE PArr, ParallelListComp #-}
>
> module Test where
>
> import Control.Arrow
> import Control.Parallel
>
> dotp :: Num a => [:a:] -> [:a:] -> a
> dotp xs ys = sumP [:x * y | x <- xs | y <- ys:]
>
> ......
>
>
> Then I get the error:
>
> Not in scope 'sumP'.
>
> What I have to import to avoid this error? Where is defined sumP?
>
> Thanks in advance for any answer.
>
> Luca
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
Hi,
It seems you'll need Data.Array.Parallel.Prelude.Double, according to
http://www.haskell.org/ghc/docs/6.12-latest/html/libraries/dph-par-0.4.0/Data-Array-Parallel-Prelude-Double.html
this page has more info on using DPH
http://www.haskell.org/haskellwiki/Data_Parallel_Haskell .
--
Cheers,
Jasper
"Capable, generous men do not create victims, they nurture them."
------------------------------
Message: 3
Date: Thu, 9 Dec 2010 10:35:04 -0800
From: dan portin <[email protected]>
Subject: [Haskell-beginners] Functional Dependencies
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I was trying to make a class of "flattenable" data structures in Haskell. My
first thought was to use multi-parameter type classes to assert a relation
between two data types, one which is flattened and another which holds
flattenable elements. Such a class is the class *F* below without the
functional dependency. When given an instance declaration like *F Tree []*,
applying *flt* to a structure fails with messages like *no instance for `F
Tree m`*. I ended up writing the following (where *foldT* is fold over
trees, etc.), in order to avoid said errors:
class (Functor m, Monad m) => F t m | t -> m where
flt :: t a -> m a
unflt :: F t' m => t' (t a) -> m a
unflt = join . fmap flt . flt
instance F Tree [] where flt = foldT (\a b c -> a : b ++ c) []
instance F Maybe [] where flt = maybeToList
Now, I would like to have *F* be a relation between a flattenable data type
and, for instance, a monoid in which I can accumulate the flattened data
type. Two things: I can't get a monoid constraint to operate properly over
the variable *m* in *unflt*. This fails with messages like *no instance for
`Monoid Tree [Integer]`*, and so on. I'm not sure why. Secondly, I would
like to be able to have *flt* be able to return different "container
structures", e.g., a custom sequence or a list. But the functional
dependency I introduced prohibits this.
How would you handle this problem? Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101209/4ebb8b45/attachment-0001.htm>
------------------------------
Message: 4
Date: Thu, 9 Dec 2010 16:02:11 -0800
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Disjunction
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I recently was writing code long these lines.
f x = p1 x || p2 x || ... || pn x
I would have liked to write that in pointfree form but couldn't find a
library function to do it.
I created this.
disj :: [a -> Bool] -> a -> Bool
disj ps = (\x -> or $ map ($x) ps)
disj2 p1 p2 = disj [p1, p2]
disj3 p1 p2 p3 = disj [p1, p2]
disj4 p1 p2 p3 p4 = disj [p1, p2]
...
With that I can write my function as follows.
f = disj pi p2 p3 ... pn
Is there a standard way to do this?
*
-- Russ*
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101209/f73a7b2d/attachment-0001.htm>
------------------------------
Message: 5
Date: Thu, 9 Dec 2010 18:13:50 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Disjunction
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 9, 2010 at 6:02 PM, Russ Abbott <[email protected]> wrote:
> I recently was writing code long these lines.
>
> f x = p1 x || p2 x || ... || pn x
>
> I would have liked to write that in pointfree form but couldn't find a
> library function to do it.
>
> I created this.
>
> disj :: [a -> Bool] -> a -> Bool
> disj ps = (\x -> or $ map ($x) ps)
>
> disj2 p1 p2 = disj [p1, p2]
> disj3 p1 p2 p3 = disj [p1, p2]
> disj4 p1 p2 p3 p4 = disj [p1, p2]
> ...
>
> With that I can write my function as follows.
>
> f = disj pi p2 p3 ... pn
>
> Is there a standard way to do this?
>
Assuming you have in instance of Applicative for ((->) r) in scope:
(<||>) :: (r -> Bool) -> (r -> Bool) -> (r -> Bool)
(<||>) = liftA2 (||)
then you could say:
f = p1 <||> p2 <||> p3 ...
Antoine
------------------------------
Message: 6
Date: Thu, 9 Dec 2010 18:15:38 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Disjunction
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 9, 2010 at 6:13 PM, Antoine Latter <[email protected]> wrote:
> On Thu, Dec 9, 2010 at 6:02 PM, Russ Abbott <[email protected]> wrote:
>> I recently was writing code long these lines.
>>
>> f x = p1 x || p2 x || ... || pn x
>>
>> I would have liked to write that in pointfree form but couldn't find a
>> library function to do it.
>>
>> I created this.
>>
>> disj :: [a -> Bool] -> a -> Bool
>> disj ps = (\x -> or $ map ($x) ps)
>>
>> disj2 p1 p2 = disj [p1, p2]
>> disj3 p1 p2 p3 = disj [p1, p2]
>> disj4 p1 p2 p3 p4 = disj [p1, p2]
>> ...
>>
>> With that I can write my function as follows.
>>
>> f = disj pi p2 p3 ... pn
>>
>> Is there a standard way to do this?
>>
>
> Assuming you have in instance of Applicative for ((->) r) in scope:
>
> (<||>) :: (r -> Bool) -> (r -> Bool) -> (r -> Bool)
> (<||>) = liftA2 (||)
>
> then you could say:
>
> f = p1 <||> p2 <||> p3 ...
>
And if you're not interested in playing tricks with liftA2 there's always:
p1 <||> p2 = \x -> p1 x || p2 x
Antoine
------------------------------
Message: 7
Date: Thu, 09 Dec 2010 19:27:26 -0500
From: "Edward Z. Yang" <[email protected]>
Subject: Re: [Haskell-beginners] Disjunction
To: Russ Abbott <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <1291940740-sup-1...@ezyang>
Content-Type: text/plain; charset=UTF-8
We can use a standard trick for poly-variadic functions.
{-# LANGUAGE FlexibleInstances #-}
class PolyDisj t where
disj :: Bool -> t
instance PolyDisj Bool where
disj x = x
instance PolyDisj t => PolyDisj (Bool -> t) where
disj x y = disj (x || y)
And a test:
*Main> disj False False False :: Bool
False
*Main> disj False False False True :: Bool
True
You need to somehow give the expression a type otherwise
it won't know which instance to use.
Edward
------------------------------
Message: 8
Date: Fri, 10 Dec 2010 11:30:00 +1000
From: Tony Morris <[email protected]>
Subject: Re: [Haskell-beginners] Disjunction
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 10/12/10 10:02, Russ Abbott wrote:
> I recently was writing code long these lines.
>
> f x = p1 x || p2 x || ... || pn x
>
> I would have liked to write that in pointfree form but couldn't find a
> library function to do it.
>
> I created this.
>
> disj :: [a -> Bool] -> a -> Bool
> disj ps = (\x -> or $ map ($x) ps)
>
> disj2 p1 p2 = disj [p1, p2]
> disj3 p1 p2 p3 = disj [p1, p2]
> disj4 p1 p2 p3 p4 = disj [p1, p2]
> ...
>
> With that I can write my function as follows.
>
> f = disj pi p2 p3 ... pn
>
> Is there a standard way to do this?
> /
> -- Russ/
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
disj = fmap or . sequence
--
Tony Morris
http://tmorris.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101210/04c1e95e/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 12
*****************************************