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:  Sankey Diagram with monads (Adrian May)
   2. Re:  Q 2 of 2: GUI and turnkey compiler? (Tim Perry)
   3. Re:  Sankey Diagram with monads (Adrian May)


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

Message: 1
Date: Sat, 1 Jun 2013 00:31:17 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Sankey Diagram with monads
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cad-ubzfx2vmnt+fbtjagwcnu1ez1pyaxniuo7cj6za1bwo1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks, but I still don't know how to fix it.

In the meantime, I'm struggling with something more basic. I plan to write
a basic monad that puts diagrams on top of each other, then I'll let State
take care of pushing the origin and angle along (turtle style). But I'm
already stuck on that basic monad.

It's >>= has to explicitly use the fact that each monad has a journey there
and a journey back. The thing on the right of >>= will be inserted in
between them.  But I always get either "something is a rigidly bound type
variable" or "Monad should have kind * -> *"

I just don't know how this is supposed to work.

I want the monad to contain two trails, in the sense of the Diagrams
module. If I bind two of them together, for the time being, I'll just stick
them on top of each other (at least I think the State monad will rescue me
from that.) I have no particular reason to tell the thing on the right of
>>= about the thing on the left. Neither do I have a reason for >>= to be
polymorphic.

Right now I'm thinking that I'll have to define a class for things that
provide a journey there and a journey back. I'd rather not, because there's
only one of them but I can't seem to restrict the game any other way, but
this way isn't helping either.

Ideally I'd be able to write something like this:

data Sankey = Sankey {there, back :: Trail R2}

instance Monad Sankey where
  return t b = Sankey t b
  l@(Sankey t b) >>= f = let (Sankey t' b') = f l in
     Sankey (t <> t') (b <> b')

although I have no reason to pass l to f. But the compiler barfs anyway. I
feel that Haskell is more complicated than what I'm trying to do. Under
duress I tried:

class Pic a where
  there :: a -> Trail R2
  back  :: a -> Trail R2

data Trails p = Trails p

instance (Pic p) => Monad (Trails p) where
  return = Trails
  (Trails l) >>= f = let (Trails r) = f l in
    ((there l <> there r),(back r <> back l))


But it doesn't like that either. What am I missing?

Adrian.














On 31 May 2013 23:42, Brandon Allbery <[email protected]> wrote:

> On Fri, May 31, 2013 at 11:06 AM, Adrian May <
> [email protected]> wrote:
>
>> Well I figured out that I should be using the State monad, but it seems
>> not to be behaving like most of the tutorials on the web. Did the syntax
>> change? ....
>>
>
> mtl-2.x changed all the base monads (State, Reader, Writer, etc.) from
> standalone to being transformers atop an Identity monad; this cleans up the
> implementation considerably (since we don't have almost exactly the same
> code for both the standalone and transformer versions, but means that all
> uses of the standalone constructors must be replaced with functions that
> build the appropriate transformer. (e.g. State becomes state, unless you
> want to spell it out as StateT Identity.)
>
> --
> brandon s allbery kf8nh                               sine nomine
> associates
> [email protected]
> [email protected]
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> 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/20130601/331ee414/attachment-0001.htm>

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

Message: 2
Date: Fri, 31 May 2013 11:37:47 -0700
From: Tim Perry <[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"

GHC is a compiler. 

Ensuring all the necessary libraries are installed is the work of an installer. 

That said, it is *nice* when compilers will statically link your executable. 

Tim Perry
(916) 505-3634


On May 31, 2013, at 9:30 AM, Giacomo Tesio <[email protected]> wrote:

> I'm wondering why there's no tool that build an EXE that contains everything 
> is needed. statically linking anything that is required... is there any 
> problem with ghc here?
> 
> 
> Giacomo
> 
> 
> On Fri, May 31, 2013 at 5:28 PM, emacstheviking <[email protected]> wrote:
>> Whatever he said. All I know is that the last time I copied a binary across 
>> to another box it failed with a "missing libgmp.so" message! Beware!!
>> 
>> On 31 May 2013 15:13, Brandon Allbery <[email protected]> wrote:
>>> On Fri, May 31, 2013 at 9:03 AM, emacstheviking <[email protected]> wrote:
>>>> 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.
>>> 
>>> libgmp? I think there are ways to make that get statically linked as well, 
>>> although various platforms (Debian derivatives, mostly) strongly discourage 
>>> doing this, to the extent that they modify their packaged ghc to force a 
>>> dependency on the system gmp library (and, somewhat ironically, are also 
>>> the ones most prone to having no or an incompatible version installed at 
>>> runtime).
>>> 
>>> -- 
>>> brandon s allbery kf8nh                               sine nomine associates
>>> [email protected]                                  [email protected]
>>> unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
>>> 
>>> _______________________________________________
>>> 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/e6e858f9/attachment-0001.htm>

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

Message: 3
Date: Sat, 1 Jun 2013 02:59:55 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Sankey Diagram with monads
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cad-ubzhuqs_enftufb4ogq_9rojfpxi9mwc8mnccskewnk8...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It got a lot easier when I forgot all about the monads:


type SaState = ( P2, CircleFrac, Double )
type SaPic =   ( (Trail R2), (Trail R2) )
type SaWorld = ( SaPic, SaState )

type SaAct = SaState -> SaWorld

bigbang :: Double -> SaWorld
bigbang w = ((mempty,mempty), (origin,0,w))

(>%) :: SaWorld -> SaAct -> SaWorld
((t1,b1),s1) >% f = let ((t2,b2),s2) = f s1 in ((t1<>t2,b2<>b1),s2)

(>%=) :: SaAct -> SaAct -> SaAct
f >%= g = \s1 ->
  let ((t2,b2),s2) = f s1 in
  let ((t3,b3),s3) = g s2 in
  ((t2<>t3,b3<>b2),s3)

saVia :: Double -> SaAct
saVia l (p,a,w) =
  (
    ( hrule l # translateX (l/2) # translateY (w/2) # rotate a
    , hrule (-l) # translateX (l/2) # translateY (-w/2) # rotate a
    )
    ,
    (p .+^ (unitX # scale l # rotate a),a,w)
  )

saTo :: SaAct
saTo (p,a,w) =
  (
    ( hrule   w  # translateX (-w/2) # rotate (-0.125 :: CircleFrac) #
scale 0.7071 # translateX (w/2) # rotate a # translate (origin .-. p)
    , hrule (-w) # translateX (-w/2) # rotate ( 0.125 :: CircleFrac) #
scale 0.7071 # translateX (w/2) # rotate a # translate (origin .-. p)
    )
    ,
    (p,a,0)
  )

saTurn :: Double -> CircleFrac -> SaAct
saTurn 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
  (
    ( 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)
  )

saSplit :: [(Double, SaAct)] -> SaAct
saSplit fs (p,a,w) =
let (placed,_) = ( foldl ( \(l,t) -> \(i,f) -> ( l++[( ( p .+^ (unitY #
rotate a # scale (((t+i/2)-0.5)*w)), a, w*i) ,f )],t+i) ) ([],0) fs ) in
let ws = map (\(b,f)-> f b) placed in
((foldl (<>) mempty (map (\((tt,bb),_)->tt<>bb) ws),mempty),(origin,0,0))

p3 = bigbang 5 >% (saVia 10 >%= (saSplit
[ (0.80,(saVia 10 >%= saTo))
, (0.20,saTurn 1 (-0.25) >%= (saVia 2 >%= (saSplit
[ (0.10,saTurn 1 (0.25) >%= (saVia 5 >%= saTo))
, (0.80,(saVia 3 >%= saTo))
, (0.10,saTurn 1 (-0.25) >%= (saVia 5 >%= saTo))
] )))
] ))

pic3 = let p = fst $ p3 in
(strokeT $ close $ (fst p) <> (snd p) ) # fc red


But still I feel I'm missing something.

Adrian.



On 1 June 2013 00:31, Adrian May <[email protected]> wrote:

> Thanks, but I still don't know how to fix it.
>
> In the meantime, I'm struggling with something more basic. I plan to write
> a basic monad that puts diagrams on top of each other, then I'll let State
> take care of pushing the origin and angle along (turtle style). But I'm
> already stuck on that basic monad.
>
> It's >>= has to explicitly use the fact that each monad has a journey
> there and a journey back. The thing on the right of >>= will be inserted in
> between them.  But I always get either "something is a rigidly bound type
> variable" or "Monad should have kind * -> *"
>
> I just don't know how this is supposed to work.
>
> I want the monad to contain two trails, in the sense of the Diagrams
> module. If I bind two of them together, for the time being, I'll just stick
> them on top of each other (at least I think the State monad will rescue me
> from that.) I have no particular reason to tell the thing on the right of
> >>= about the thing on the left. Neither do I have a reason for >>= to be
> polymorphic.
>
> Right now I'm thinking that I'll have to define a class for things that
> provide a journey there and a journey back. I'd rather not, because there's
> only one of them but I can't seem to restrict the game any other way, but
> this way isn't helping either.
>
> Ideally I'd be able to write something like this:
>
> data Sankey = Sankey {there, back :: Trail R2}
>
> instance Monad Sankey where
>   return t b = Sankey t b
>   l@(Sankey t b) >>= f = let (Sankey t' b') = f l in
>      Sankey (t <> t') (b <> b')
>
> although I have no reason to pass l to f. But the compiler barfs anyway. I
> feel that Haskell is more complicated than what I'm trying to do. Under
> duress I tried:
>
> class Pic a where
>   there :: a -> Trail R2
>   back  :: a -> Trail R2
>
> data Trails p = Trails p
>
> instance (Pic p) => Monad (Trails p) where
>   return = Trails
>   (Trails l) >>= f = let (Trails r) = f l in
>     ((there l <> there r),(back r <> back l))
>
>
> But it doesn't like that either. What am I missing?
>
> Adrian.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On 31 May 2013 23:42, Brandon Allbery <[email protected]> wrote:
>
>> On Fri, May 31, 2013 at 11:06 AM, Adrian May <
>> [email protected]> wrote:
>>
>>> Well I figured out that I should be using the State monad, but it seems
>>> not to be behaving like most of the tutorials on the web. Did the syntax
>>> change? ....
>>>
>>
>> mtl-2.x changed all the base monads (State, Reader, Writer, etc.) from
>> standalone to being transformers atop an Identity monad; this cleans up the
>> implementation considerably (since we don't have almost exactly the same
>> code for both the standalone and transformer versions, but means that all
>> uses of the standalone constructors must be replaced with functions that
>> build the appropriate transformer. (e.g. State becomes state, unless you
>> want to spell it out as StateT Identity.)
>>
>> --
>> brandon s allbery kf8nh                               sine nomine
>> associates
>> [email protected]
>> [email protected]
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>> _______________________________________________
>> 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/20130601/beb94f52/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 3.png
Type: image/png
Size: 13507 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130601/beb94f52/attachment.png>

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

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


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

Reply via email to