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:  Getting Gtk2Hs working in windows (aditya siram)
   2.  Question about functors (or maybe not...) (Patrick LeBoutillier)
   3. Re:  Question about functors (or maybe not...)
      (Felipe Almeida Lessa)
   4. Re:  Unit conversion (Tom Murphy)


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

Message: 1
Date: Fri, 18 Mar 2011 20:42:53 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Getting Gtk2Hs working in windows
To: Kyle Murphy <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Please update the wiki with your findings.
-deech

On Fri, Mar 18, 2011 at 8:24 PM, Kyle Murphy <[email protected]> wrote:
> I got Gtk2Hs installed finally, although I'm not happy with at least one
> step of the process. First of all, the process outlined on the wiki is
> incorrect, in that the glade installer apparently does not come with
> everything you need in order to build the gtk module. Downloading the dev
> gtk all in one bundle off the gtk site gets you most of the way to a working
> install. It appears the environment variables mentioned in the wiki are also
> slightly off. You need to set the following:
>
> GTK_HOME: Location you unpacked the gtk all in one bundle to.
> INCLUDE: %GTK_HOME%\include
> LIB: %GTK_HOME%\lib
> PATH: %GTK_HOME%\bin
> PKG_CONFIG_PATH: %GTK_HOME%\lib\pkgconfig
>
> Furthermore at least in the configuration I have it appears that running
> "cabal install gtk" will fail. Instead you need to run "cabal install gtk
> --global", and you need to make sure that the cmd prompt you run it from is
> running with administrator permissions. I haven't gotten the glade bindings
> installed yet, but that should only be a matter of time. Most likely I'll
> have to go grab some other dev package off the gtk site.
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
> On Fri, Mar 18, 2011 at 20:18, Kyle Murphy <[email protected]> wrote:
>>
>> Yes, I read the thread you made. Working on a hunch I downloaded the Gtk+
>> all in one bundle and installed it but used all the environment variables
>> defined by the glade installer (I just changed GTK_HOME to the newly
>> downloaded all in one bundle and updated the other variables as needed).
>> This seems to have fixed the libraries not being found, but it now looks
>> like I'm being bitten by another issue entirely. I'm getting the following
>> error:
>> Registering cairo-0.12.0...
>> Installing library in
>> C:\Users\Kyle\AppData\Roaming\cabal\cairo-0.12.0\ghc-7.0.2
>> Registering cairo-0.12.0...
>> setup.exe: internal error: unexpected package db stack: [UserPackageDB]
>>
>> What's weird is that I found a ticket for cabal that's similar to this one
>> (http://hackage.haskell.org/trac/hackage/ticket/731) but it's specifically
>> in the case of using a custom package db which I don't think I'm doing
>> (unless the gtk package is doing something really weird). Maybe this is a
>> more general issue with the latest version of Cabal? Just in case the output
>> from running cabal --version:
>>
>> cabal-install version 0.10.2
>> using version 1.10.1.0 of the Cabal library
>>
>> I'm going to keep experimenting and hopefully find a way to get this all
>> working.
>>
>> -R. Kyle Murphy
>> --
>> Curiosity was framed, Ignorance killed the cat.
>>
>>
>> On Fri, Mar 18, 2011 at 19:23, aditya siram <[email protected]>
>> wrote:
>>>
>>> Hi Kyle,
>>> I ran into this exact issue and fixed it on my Windows box at work but
>>> I forgot how. I won't be back there till Monday, can I get back to you
>>> then?
>>>
>>> If this is still an issue could send me email on Monday morning to remind
>>> me?
>>>
>>> thanks...
>>> -deech
>>>
>>> On Fri, Mar 18, 2011 at 5:49 PM, Kyle Murphy <[email protected]> wrote:
>>> > I'm trying to follow the instructions provided on
>>> > http://www.haskell.org/haskellwiki/Gtk2Hs to install Gtk2Hs in Windows
>>> > 7 (64
>>> > bit) and running into problems.
>>> > Originally I was trying to get wxHaskell installed, but it kept
>>> > crashing
>>> > trying to build the monolithic library due to an apparent bug in the
>>> > latest
>>> > port of GCC, so after talking with some of the people in #haskell I was
>>> > advised that Gtk2Hs was better supported and might be easier to get
>>> > working.
>>> > For the most part, that appears to be true but I (as well as several
>>> > others
>>> > it seems) am running into a problem where cabal can't seem to find
>>> > quite a
>>> > few of the Gtk+ libraries (specifically z, cairo, gobject, glib, and
>>> > intl).
>>> > Near as I can tell everything should be functioning, and running
>>> > pkg-config
>>> > --modversion glib-2.0 outputs "2.20.3" so at least pkg-config seems to
>>> > be
>>> > able to find glib. Looking in the Gtk+\lib\pkgconfig folder I see pc
>>> > files
>>> > for everything but z and intl listed. Running cabal install
>>> > gtk2hs-buildtools also succeeds, it's only when I get to the cabal
>>> > install
>>> > gtk step that things fail.
>>> >
>>> > cmd console output for the usual environment variables:
>>> >
>>> > INCLUDE: C:\libxml\include;C:\Program Files (x86)\Gtk+\include
>>> > LIB: C:\libxml\lib;C:\Program Files (x86)\Gtk+\lib
>>> > PKG_CONFIG_PATH: C:\libxml\lib\pkgconfig;C:\Program Files
>>> > (x86)\Gtk+\lib\pkgconfig
>>> >
>>> > I trimmed the PATH output below for everyones sanity. The vast majority
>>> > was
>>> > stuff in the Windows folder or one of dozens of entries dumped in there
>>> > by
>>> > some version or other of Java.
>>> >
>>> > PATH:
>>> > C:\Program Files (x86)\Haskell\bin;
>>> > C:\Program Files (x86)\Haskell Platform\2011.2.0.0\lib\extralibs\bin;
>>> > C:\Program Files (x86)\Haskell Platform\2011.2.0.0\bin;
>>> > C:\MinGW\bin;
>>> > C:\Users\Kyle\AppData\Roaming\cabal\bin;
>>> > C:\Program Files (x86)\Haskell\bin;
>>> > C:\Program Files (x86)\Gtk+\bin
>>> >
>>> > The exact error I'm getting when building is the following:
>>> > C:\Users\Kyle>cabal install gtk
>>> > Warning: The package list for 'hackage.haskell.org' is 23 days old.
>>> > Run 'cabal update' to get the latest list of available packages.
>>> > Resolving dependencies...
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\Gtk2HsSetup.hs:25:2:
>>> > warning: #warning Setup.hs is guessing the version of Cabal. If
>>> > compilationof Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal
>>> > version
>>> > 1.x.0 when building (prefixed by --ghc-option= when using the 'cabal'
>>> > command)
>>> > [1 of 2] Compiling Gtk2HsSetup????? (
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\Gtk2HsSetup.hs,
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\dist\setup\Gtk2HsSetup.o
>>> > )
>>> > [2 of 2] Compiling Main???????????? (
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\Setup.hs,
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\dist\setup\Main.o
>>> > )
>>> > Linking
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\cairo-0.12.05760\cairo-0.12.0\dist\setup\setup.exe
>>> > ...
>>> > Configuring cairo-0.12.0...
>>> > setup.exe: Missing dependencies on foreign libraries:
>>> > * Missing C libraries: z, cairo
>>> > This problem can usually be solved by installing the system packages
>>> > that
>>> > provide these libraries (you may need the "-dev" versions). If the
>>> > libraries
>>> > are already installed but in a non-standard location then you can use
>>> > the
>>> > flags --extra-include-dirs= and --extra-lib-dirs= to specify where they
>>> > are.
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\Gtk2HsSetup.hs:25:2:
>>> > warning: #warning Setup.hs is guessing the version of Cabal. If
>>> > compilation
>>> > of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0
>>> > when
>>> > building (prefixed by --ghc-option= when using the 'cabal' command)
>>> > [1 of 2] Compiling Gtk2HsSetup????? (
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\Gtk2HsSetup.hs,
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\dist\setup\Gtk2HsSetup.o
>>> > )
>>> > [2 of 2] Compiling Main???????????? (
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\Setup.hs,
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\dist\setup\Main.o
>>> > )
>>> > Linking
>>> >
>>> > C:\Users\Kyle\AppData\Local\Temp\glib-0.12.05760\glib-0.12.0\dist\setup\
>>> > setup.exe ...
>>> > Configuring glib-0.12.0...
>>> > setup.exe: Missing dependencies on foreign libraries:
>>> > * Missing C libraries: gobject-2.0, glib-2.0, intl
>>> > This problem can usually be solved by installing the system packages
>>> > that
>>> > provide these libraries (you may need the "-dev" versions). If the
>>> > libraries
>>> > are already installed but in a non-standard location then you can use
>>> > the
>>> > flags --extra-include-dirs= and --extra-lib-dirs= to specify where they
>>> > are.
>>> > cabal: permission denied
>>> >
>>> >
>>> > -R. Kyle Murphy
>>> > --
>>> > Curiosity was framed, Ignorance killed the cat.
>>> >
>>> > _______________________________________________
>>> > Beginners mailing list
>>> > [email protected]
>>> > http://www.haskell.org/mailman/listinfo/beginners
>>> >
>>> >
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



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

Message: 2
Date: Fri, 18 Mar 2011 22:00:33 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] Question about functors (or maybe not...)
To: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I'm writing a music library and have the following types and functions:

data Note = C | D | E | F | G | A | B | Sharp Note | Flat Note
raise C = Sharp C

data Quality = Major | Minor

data Chord = Chord Quality Note  -- Note is the root
data Scale = Scale Quality Note  -- Note is the tonic

What I would like to do is to be able to lift the raise function and
apply it to
Chords and Scales. Something like this:

fmap raise (Chord Major C) = Chord Major (Sharp C)

But these are not functors as it doesn't seem to make sense for them to
be polymorphic. A chord can't really made of anything except Notes.


Does anybody have any ideas?

Patrick

-- 
=====================
Patrick LeBoutillier
Rosem?re, Qu?bec, Canada



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

Message: 3
Date: Sat, 19 Mar 2011 02:53:05 +0000
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Question about functors (or maybe
        not...)
To: Patrick LeBoutillier <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Sat, Mar 19, 2011 at 2:00 AM, Patrick LeBoutillier
<[email protected]> wrote:
> Hi,
>
> I'm writing a music library and have the following types and functions:
>
> data Note = C | D | E | F | G | A | B | Sharp Note | Flat Note
> raise C = Sharp C
>
> data Quality = Major | Minor
>
> data Chord = Chord Quality Note ?-- Note is the root
> data Scale = Scale Quality Note ?-- Note is the tonic
>
> What I would like to do is to be able to lift the raise function and
> apply it to
> Chords and Scales. Something like this:
>
> fmap raise (Chord Major C) = Chord Major (Sharp C)
>
> But these are not functors as it doesn't seem to make sense for them to
> be polymorphic. A chord can't really made of anything except Notes.

You can write your own plain old functions:

mapChord :: (Note -> Note) -> Chord -> Chord
mapChord f (Chord q n) = Chord q (f n)

mapScale :: (Note -> Note) -> Scale -> Scale
mapScale f (Scale q n) = Scale q (f n)

You can also create your own type class, if that's convenient for you

class NoteMap a where
  noteMap :: (Note -> Note) -> a -> a

instance NoteMap Chord where noteMap = mapChord
instance NoteMap Scale where noteMap = mapScale

HTH, =)

-- 
Felipe.



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

Message: 4
Date: Fri, 18 Mar 2011 23:02:19 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Unit conversion
To: Magnus Therning <[email protected]>, [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

On Fri, Mar 18, 2011 at 5:02 AM, Magnus Therning <[email protected]>
 wrote:

> On Thu, Mar 17, 2011 at 21:17, Tom Murphy <[email protected]> wrote:
> > Hi All,
> >      Is there a good way to easily convert between units?
> >      For example, let's say I have a data type:
> >      data Volumes = Teaspoon | Tablespoon | Slice | FluidOunces
> >      ... and I want to define an infix function '<+>', which adds
> together
> > amounts of food:
> >      (1, Slice, cake) <+> (1, Volume Tablespoon, sugar) <+> (32, Volume
> > FluidOunces, almondMilk)
> >      Which would return:
> >      (3200, Teaspoons)
> >      What is the most efficient way to define equivalency/conversion
> between
> > these measures?
> >      I remember an interesting method for celsius-farenheit conversion in
> > Higher-Order Perl, using function composition, but that was between only
> 2
> > units. I'd like something where I don't have to provide n^2 definitions.
>
> I wrote two blog posts on something that sounds related:
> http://therning.org/magnus/archives/354
> http://therning.org/magnus/archives/355
>
> Maybe they could help.
>
> /M
>
> --
> Magnus Therning                      OpenPGP: 0xAB4DFBA4
> email: [email protected]   jabber: [email protected]
> twitter: magthe               http://therning.org/magnus







So given
data Measure = M Volume Float
  deriving (Show, Eq)
data Volume = Slice
            | FluidOunce
            | Tablespoon
            | Teaspoon
  deriving (Show, Eq)

Method one and two would be to convert all units to the smallest unit:
toTsp                           :: Measure -> Measure
[...]
toTsp (M Slice a)          = M Teaspoon (a * 350)
toTsp (M FluidOunce a) = M Teaspoon (a * 34)
[...]

Perform the addition, then convert it to a more appropriate measure (back to
Cake Slices...).
     It seems that there's a potential loss of precision, if I have to for
example convert Megaliter measures to Teaspoons.


Method three involves using typeclasses to define common "meeting points"
for the units.
So, we say that if we're adding Slices and FluidOunces, both measures should
be converted to FluidOunces before the addition.
The problem there is that, given n measurement units, we have to declare n^2
typeclass instances by hand.


Another way that I can see to do this is to define a "chain" of conversions.
I'd then "convert down" only to the smallest-common unit.

So I could define
(warning: extreme kludge ahead)
a series of "step-down"s and "step-up"s:

Given a largest-to-smallest ordering of Slice, FluidOunce, Tablespoon,
Teaspoon, I can define:

stepDown                           :: Measure -> Measure
stepDown (M Slice a)          = M FluidOunce (a * 120)
stepDown (M FluidOunce a) = M Tablespoon (a * 2)
stepUp   (M FluidOunce a)   = M Slice (a / 120)
stepUp   (M Tablespoon a)   = M FluidOunce (a / 2)
[...]


and then a function to "step" as far down as needed:

convertDown :: Measure -> Volume -> Measure
convertDown (M unit measure) goalUnit
                     | unit == goalUnit = M unit measure
                     | otherwise        = fun5 (stepDown (M unit measure))
 goalUnit



And then if I wanted to add a Slice of cake to a Tablespoon of almond milk,
I'd have to find the smaller unit, convert down, perform the math and then
do a "convert up" operation.

An added benefit to this method is that defining a unit smaller than the
current smallest wouldn't involve revising the "base unit" measures.

This seems like a pretty common C.S. problem; I'm surprised I haven't been
able to find more resources about it.

Thanks for your time!

Tom
P.S. Thank you, Magnus, for those resources!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110318/c621b167/attachment.htm>

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

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


End of Beginners Digest, Vol 33, Issue 24
*****************************************

Reply via email to