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. Re:  Abstracting Data.List (Giacomo Tesio)
   2. Re:  Q 2 of 2: GUI and turnkey compiler? (Brent Yorgey)
   3. Re:  Q 2 of 2: GUI and turnkey compiler? (emacstheviking)
   4.  Sankey Diagram with monads (Adrian May)


----------------------------------------------------------------------

Message: 1
Date: Fri, 31 May 2013 12:54:13 +0200
From: Giacomo Tesio <[email protected]>
Subject: Re: [Haskell-beginners] Abstracting Data.List
To: [email protected],   The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Message-ID:
        <cahl7psekee68n+khl6brcpqym2htbpc7sxqcdavlvuk8ikh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Exactly what I Was looking for!

Thanks! :-D


Giacomo


On Fri, May 31, 2013 at 12:44 PM, Peter Hall <[email protected]>wrote:

>
> http://hackage.haskell.org/packages/archive/ListLike/3.1.4/doc/html/Data-ListLike.html
>
> Peter
>
>
> On 31 May 2013 11:16, mukesh tiwari <[email protected]> wrote:
>
>> Hi Giacomo,
>> Data.List can be abstracted using Foldable and Traversable but
>> unfortunately I could not find the functions corresponding to head, take.
>>
>> Prelude Data.Traversable Data.Foldable> :t Data.Foldable.
>> Data.Foldable.Foldable    Data.Foldable.concatMap
>> Data.Foldable.foldl'      Data.Foldable.foldrM
>> Data.Foldable.minimum     Data.Foldable.sequenceA_
>> Data.Foldable.all         Data.Foldable.elem
>> Data.Foldable.foldl1      Data.Foldable.forM_
>> Data.Foldable.minimumBy   Data.Foldable.sequence_
>> Data.Foldable.and         Data.Foldable.find
>> Data.Foldable.foldlM      Data.Foldable.for_
>> Data.Foldable.msum        Data.Foldable.sum
>> Data.Foldable.any         Data.Foldable.fold
>> Data.Foldable.foldr       Data.Foldable.mapM_
>> Data.Foldable.notElem     Data.Foldable.toList
>> Data.Foldable.asum        Data.Foldable.foldMap
>> Data.Foldable.foldr'      Data.Foldable.maximum
>> Data.Foldable.or          Data.Foldable.traverse_
>> Data.Foldable.concat      Data.Foldable.foldl
>> Data.Foldable.foldr1      Data.Foldable.maximumBy   Data.Foldable.product
>> Prelude Data.Traversable Data.Foldable> :t Data.Traversable.
>> Data.Traversable.Traversable     Data.Traversable.for
>> Data.Traversable.mapAccumR       Data.Traversable.sequenceA
>> Data.Traversable.fmapDefault     Data.Traversable.forM
>> Data.Traversable.mapM            Data.Traversable.traverse
>> Data.Traversable.foldMapDefault  Data.Traversable.mapAccumL
>> Data.Traversable.sequence
>> Prelude Data.Traversable Data.Foldable> :i Foldable
>> class Foldable t where
>>   fold :: Data.Monoid.Monoid m => t m -> m
>>   foldMap :: Data.Monoid.Monoid m => (a -> m) -> t a -> m
>>   Data.Foldable.foldr :: (a -> b -> b) -> b -> t a -> b
>>   foldr' :: (a -> b -> b) -> b -> t a -> b
>>   Data.Foldable.foldl :: (a -> b -> a) -> a -> t b -> a
>>   foldl' :: (a -> b -> a) -> a -> t b -> a
>>   Data.Foldable.foldr1 :: (a -> a -> a) -> t a -> a
>>   Data.Foldable.foldl1 :: (a -> a -> a) -> t a -> a
>>       -- Defined in `Data.Foldable'
>> instance Foldable [] -- Defined in `Data.Foldable'
>> instance Foldable Maybe -- Defined in `Data.Foldable'
>> Prelude Data.Traversable Data.Foldable> :i Tr
>> Traversable  True
>> Prelude Data.Traversable Data.Foldable> :i Traversable
>> class (Functor t, Foldable t) => Traversable t where
>>   traverse ::
>>     Control.Applicative.Applicative f => (a -> f b) -> t a -> f (t b)
>>   sequenceA ::
>>     Control.Applicative.Applicative f => t (f a) -> f (t a)
>>   Data.Traversable.mapM :: Monad m => (a -> m b) -> t a -> m (t b)
>>   Data.Traversable.sequence :: Monad m => t (m a) -> m (t a)
>>       -- Defined in `Data.Traversable'
>> instance Traversable [] -- Defined in `Data.Traversable'
>> instance Traversable Maybe -- Defined in `Data.Traversable'
>> Prelude Data.Traversable Data.Foldable> :t foldMap
>> foldMap
>>   :: (Foldable t, Data.Monoid.Monoid m) => (a -> m) -> t a -> m
>>
>> -Mukesh
>>
>>
>> On Fri, May 31, 2013 at 2:26 PM, Giacomo Tesio <[email protected]> wrote:
>>
>>> I'm looking for a class abstracting Data.List. I mean something that
>>> enable the use of say head, map, take and so on into different kind of
>>> types.
>>>
>>> Is there already something like that?
>>>
>>>
>>> Giacomo
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130531/dc695e3b/attachment-0001.htm>

------------------------------

Message: 2
Date: Fri, 31 May 2013 08:08:42 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Q 2 of 2: GUI and turnkey compiler?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Thu, May 30, 2013 at 06:54:54PM -0400, Gan Uesli Starling wrote:
> Perl and Python both have GUI interfaces, which are handy for
> publishing little give-away apps, as I used to do quite a lot in
> Perl/Tk and also in ancient of days on JForth. Also to make give-away
> apps, there needs to be a turn-key compiler, something into which I'd
> feed code and out would come an *.exe (albeit quite bloated in size)
> that ran on any PC which did not have Haskell already installed.

By default, GHC produces statically linked executables, which (if I'm
not mistaken) can be distributed to anyone with the same machine
architecture, whether they have anything Haskell-related installed or
not.

-Brent



------------------------------

Message: 3
Date: Fri, 31 May 2013 14:03:51 +0100
From: emacstheviking <[email protected]>
Subject: Re: [Haskell-beginners] Q 2 of 2: GUI and turnkey compiler?
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAEiEuUL_rDVg1D9oes5ed1UYhtCEZhBLB6tJa0A6e8Bp=zu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I tried that too... but I think I fell foul to a missing library for the
arbitrary length arithmetic. can't remember the name of it off-hand though.

On 31 May 2013 13:08, Brent Yorgey <[email protected]> wrote:

> On Thu, May 30, 2013 at 06:54:54PM -0400, Gan Uesli Starling wrote:
> > Perl and Python both have GUI interfaces, which are handy for
> > publishing little give-away apps, as I used to do quite a lot in
> > Perl/Tk and also in ancient of days on JForth. Also to make give-away
> > apps, there needs to be a turn-key compiler, something into which I'd
> > feed code and out would come an *.exe (albeit quite bloated in size)
> > that ran on any PC which did not have Haskell already installed.
>
> By default, GHC produces statically linked executables, which (if I'm
> not mistaken) can be distributed to anyone with the same machine
> architecture, whether they have anything Haskell-related installed or
> not.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130531/29ad3c03/attachment-0001.htm>

------------------------------

Message: 4
Date: Fri, 31 May 2013 21:16:17 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Sankey Diagram with monads
To: "[email protected]" <[email protected]>
Message-ID:
        <cad-ubzh-ksk_8wmvbo5lgdoblkjc7twknrg1hqvzmead7sw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi all,

Take a look at this disaster area, or just scroll down to where I come to
the point...

=======================

type SankeyBrain = (P2,CircleFrac,Double) -- like a turtle plus width
data SankeyWorld tb = SankeyWorld ((Trail R2,Trail R2),tb) --outgoing and
returning trails, plus brain

emptySankey :: SankeyWorld SankeyBrain
emptySankey = SankeyWorld ((mempty,mempty),(origin,0,0))

sankeyFrom:: CircleFrac -> Double -> SankeyWorld SankeyBrain
sankeyFrom a w = SankeyWorld ((mempty,mempty),(p2 (0,0),a,w)) -- kick off
with an angle and width

instance Monad SankeyWorld where
  return a = SankeyWorld ((mempty,mempty), a) --never use this
  (SankeyWorld l) >>= f = let (SankeyWorld r) = f (snd l) in -- out = left
then right, return = right then left
 SankeyWorld ( (((fst.fst) l <> (fst.fst) r),((snd.fst) r <> (snd.fst)
l)),(snd r)   )

sankeyVia :: Double -> SankeyBrain -> SankeyWorld SankeyBrain
sankeyVia d (p,a,w) =
  let -- draw parallel lines and move them into place
    l1 = hrule 1 # scaleX d    # translateX (d/2) # translateY (w/2)  #
rotate a # translate (origin .-. p)
    l2 = hrule 1 # scaleX (-d) # translateX (d/2) # translateY (-w/2) #
rotate a # translate (origin .-. p)
  in SankeyWorld ( ( l1 , l2 ) , ( p .+^ (unitX # scale d # rotate a), a,
w) )

sankeyTo :: SankeyBrain -> SankeyWorld SankeyBrain
sankeyTo (p,a,w) = SankeyWorld ( --arrow at the end of the flow
  ( hrule w    # translateX (w/2) # translateY (w/2)  # rotate
(-1/8::CircleFrac) #  scale (0.7071) # rotate a # translate (origin .-. p)
  , hrule (-w) # translateX (w/2) # translateY (-w/2) # rotate
 (1/8::CircleFrac) #  scale (0.7071) # rotate a # translate (origin .-. p)
  ), (p,a,w))


sankeyTurn r a' (p,a,w) = let (outr, inr, qu) = if a'>=0 then (r, -w-r,
-0.25::CircleFrac) else (-w-r, r, 0.25::CircleFrac) in
  SankeyWorld ( -- turn a corner with nice round edges
( arc' outr (a+qu) (a+a'+qu)  # translate (unitY # rotate (a+a' )# scale w)
  , arc' inr  (a+a'+qu) (a+qu) # translate (unitY # rotate (a+a' )# scale w)
  ),(p,a+a',w))

-- bump...
sankeySplit :: [(Double, SankeyBrain -> SankeyWorld SankeyBrain)] ->
SankeyBrain -> SankeyWorld SankeyBrain
sankeySplit fs (p,a,w) = let (placed,_) = ( foldl ( \(l,t) -> \(i,c) -> (
l++[( ( p .+^ (unitY # rotate a # scale (((t+i/2)-0.5)*w)), a, w*i) ,c
)],t+i) ) ([],0) fs ) in
 foldl (\(SankeyWorld ((lo,lr),lb)) -> \(SankeyWorld ((ro,rr),rb)) ->
SankeyWorld ( ( lo <> ro , rr <> lr ), rb )  ) emptySankey $ map (\(b,f)->
f b) placed

SankeyWorld ((turtb,turta),_) =
{- This is the bit that fails:
sankeyFrom 0 5 >>= sankeyVia 5 >>=
sankeySplit
 [ (0.3, sankeyVia 10 )
, (0.7, sankeyVia 15 )
]
 -}
sankeyFrom 0 5 >>= sankeyVia 5 >>= sankeyTurn 1 (-0.125) >>= sankeyVia 10
>>= sankeyTurn 1 (0.25) >>= sankeyTo -- >>= turn 0.25 >>= forward 10 >>=
turn 0.25 >>= forward 20 >>= turn 0.25 >>= forward 10

pic3 = (strokeT (close ( turtb<>turta) )) # fc red

======================

The idea is that SankeyWorld is a monad containing two trails (outbound and
inbound) and a turtle-like state. I bind it onto functions like SankeyBrain
-> SankeyWorld, whereby >>= passes the state across. >>= draws the left
hand outward trail, then the right hand outward trail, then the right hand
inward trail, then the left hand inward trail, so it all makes a nice
polygon and I can colour it in.

sankeyFrom angle width is already a monad, sankeyVia length is such a
function and I could have sankeyTo contain () in place of the brain (i.e.
state) cos you're not supposed to continue from it.

The tricky bit is splitting the flow. I want a function that takes the
brain, splits the width according to named shares and shoves each share
into a function SankeyBrain -> SankeyWorld that might have lots more stages
and splits downwind.

It was all going fine until I discovered that if I can say m >>= f, then I
can't say f >>= f. So I don't know how to write the bits after the split.
Silly me. But what should I do instead to model Sankey diagrams splitting?
Is MonadPlus the trick? If so, am I gonna have to make [SankeyWorld] a
monad as well?

TIA,
Adrian.

PS: I rarely have any use for the polymorphism of the parameter to Monad.
In this case, it's a SankeyBrain, end of story. Is there a simpler kind of
monad that doesn't throw this complication at me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130531/d56a265f/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 59, Issue 45
*****************************************

Reply via email to