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: data constructors (Michael Mossey)
2. Re: data constructors (Michael Mossey)
3. Re: data constructors (Heinrich Apfelmus)
4. Re: data constructors (Heinrich Apfelmus)
5. Re: data constructors (Heinrich Apfelmus)
6. Re: Installing Yi With GTK Frontend (Kalman Noel)
7. Re: Partial Loading and Debugging with GHCI (Kalman Noel)
8. problem cabal install'ing hmatrix (Erik Quaeghebeur)
9. Parsec 3.0 problems (Ian Duncan)
----------------------------------------------------------------------
Message: 1
Date: Sun, 19 Apr 2009 18:25:10 -0700
From: Michael Mossey <[email protected]>
Subject: Re: [Haskell-beginners] data constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Daniel Fischer wrote:
>
> import Data.Function (on)
> import Data.List
>
> convert namedStaffs = map timeVertical verticals
> where
> nameTimedChords (name,tcs) = [(time,name,chord) | (time, chord) <- tcs]
> timedNamedChords = sort . foldr merge [] . map nameTimedChords $
> namedStaffs
> fst3 (x,_,_) = x
> verticals = groupBy ((==) `on` fst3) timedNamedChords
> timeVertical v@((t,_,_):_) = (t,[(name,chord) | (_,name,chord) <- v])
>
> ?
Hi Daniel,
Thanks, that is nice and I will learn a lot by studying it. However, a problem.
It
will be a big benefit to do this lazily because I only need to extract as many
verticals as necessary to fit on one page of layout.
I realized, as you did, that it would simplify things to care only about
NamedTimedChords:
type NamedTimedChord = (Name,Time,Chord)
Even though there is some redundancy to have every entry carry along its name
and
time, it is worth it for simplifying things. Here's what I have, to do this
lazily
and now caring only about NamedTimedChords:
toVerticals :: [[NamedTimedChord]] -> [[NamedTimedChord]]
toVerticals [] = []
toVerticals staves = firstVertical : toVerticals remainder
where
time3 (_,time,_) = time
firstVertT = minimum $ map (time3 . head) staves
usingStaves = [ s | s <- staves, time3 (head s) == firstVertT ]
notUsingStaves = [ s | s <- staves, time3 (head s) /= firstVertT ]
firstVertical = map head usingStaves
remainder = leftOfUsing ++ notUsingStaves
leftOfUsing = filter (not . null) (map tail usingStaves)
------------------------------
Message: 2
Date: Sun, 19 Apr 2009 22:24:21 -0700
From: Michael Mossey <[email protected]>
Subject: Re: [Haskell-beginners] data constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Michael Mossey wrote:
>
> toVerticals :: [[NamedTimedChord]] -> [[NamedTimedChord]]
> toVerticals [] = []
> toVerticals staves = firstVertical : toVerticals remainder
> where
> time3 (_,time,_) = time
> firstVertT = minimum $ map (time3 . head) staves
> usingStaves = [ s | s <- staves, time3 (head s) == firstVertT ]
> notUsingStaves = [ s | s <- staves, time3 (head s) /= firstVertT ]
realized I could use Data.List.partition for this
> firstVertical = map head usingStaves
> remainder = leftOfUsing ++ notUsingStaves
> leftOfUsing = filter (not . null) (map tail usingStaves)
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 3
Date: Mon, 20 Apr 2009 09:00:10 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: data constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Michael Mossey wrote:
> I want to write a function that converts the first way of organizing the
> information into the second. I tried writing types like
>
> type Chord = ...
> type Time = Double
> type Name = String
>
> type TimedChord = (Time,Chord)
> type Staff = [(Time,Chord)]
> type NamedStaff = (Name,Staff)
> type NamedChord = (Name,Chord)
> type Vertical = [NamedChord]
> type TimedVertical = (Time,Vertical)
>
> The function I want is
>
> convert :: [NamedStaff] -> [TimedVertical]
>
> As you can imagine, this is a confusing mess, with all these variants on
> named and timed things. I thought it might help to create functors
> called Named and Timed, which might help abstracting operations on named
> and timed things. For example,
>
> datatype Named a = Named { namedName :: Name, namedData :: a }
>
> instance Functor Named =
> name a :: Name
> name a = namedName a
> x `fmap` f = Named { namedName = namedName x, namedData = f $
> namedData x }
>
> Any other suggestions?
Functors sounds good to me.
data Named a = N Name a
data Timed a = T Time a
instance Functor Named where ...
instance Functor Timed where ...
convert :: Named [Timed Chord] -> Timed [Named Chord]
Bu you can also use plain type synonyms
type Named a = (Name,a)
type Timed a = (Time,a)
and write your own record selectors by hand
name :: Named a -> Name
name = fst
time :: Timed a -> Time
time = fst
value :: (b,a) -> a
value = snd
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 4
Date: Mon, 20 Apr 2009 09:01:01 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: data constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Michael Mossey wrote:
> I want to write a function that converts the first way of organizing the
> information into the second. I tried writing types like
>
> type Chord = ...
> type Time = Double
> type Name = String
>
> type TimedChord = (Time,Chord)
> type Staff = [(Time,Chord)]
> type NamedStaff = (Name,Staff)
> type NamedChord = (Name,Chord)
> type Vertical = [NamedChord]
> type TimedVertical = (Time,Vertical)
>
> The function I want is
>
> convert :: [NamedStaff] -> [TimedVertical]
>
> As you can imagine, this is a confusing mess, with all these variants on
> named and timed things. I thought it might help to create functors
> called Named and Timed, which might help abstracting operations on named
> and timed things. For example,
>
> datatype Named a = Named { namedName :: Name, namedData :: a }
>
> instance Functor Named =
> name a :: Name
> name a = namedName a
> x `fmap` f = Named { namedName = namedName x, namedData = f $
> namedData x }
>
> Any other suggestions?
Functors sounds good to me.
data Named a = N Name a
data Timed a = T Time a
instance Functor Named where ...
instance Functor Timed where ...
convert :: Named [Timed Chord] -> Timed [Named Chord]
But you can also use plain type synonyms
type Named a = (Name,a)
type Timed a = (Time,a)
and write your own record selectors by hand
name :: Named a -> Name
name = fst
time :: Timed a -> Time
time = fst
value :: (b,a) -> a
value = snd
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 5
Date: Mon, 20 Apr 2009 09:10:35 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: data constructors
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Michael Mossey wrote:
> A StaffItem can be one of several things. Let's say it can be a "chord"
> or a "control". I might like to define Chord and Control first:
>
> data Chord = Chord { duration :: Double, notes :: [Note] }
> data Control = DynamicMark Int
> | TempoMark Int
>
> Okay, so now I want to express the idea a StaffItem can be a Chord or a
> Control.
>
> data StaffItem = StaffItemChord Chord
> | StaffItemControl Control
>
> My problem is the awkward need for separately named constructors
> "StaffItemChord" and "StaffItemControl". Is there a better way? (Is this
> even right?)
Why not simply
data StaffItem = Chord { duration :: Double, notes :: [Note] }
| DynamicMark Int
| TempoMark Int
Unless you use Control and Chords in isolation, that's entirely fine.
It's basically a question of how much type safety you want. If you have
a function like
chordName :: Chord -> String
that should only with proper Chords and not Control messages, giving
it the type signature
chordName :: StaffItem -> String
is less safe; the compiler won't complain if you pass it a Control
message. If you want the compiler to complain, then building "type
towers" as you did is the way to go.
You can use predefined building blocks like Either
type StaffLabel = Either Chord Control
to build your types. There are a few methods for making things less
clumsy available, like for example
Wouter Swierstra. Data types à la carte.
http://www.cse.chalmers.se/~wouter/Publications/DataTypesALaCarte.pdf
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 6
Date: Fri, 17 Apr 2009 21:58:33 +0200
From: Kalman Noel <[email protected]>
Subject: Re: [Haskell-beginners] Installing Yi With GTK Frontend
To: aditya siram <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
aditya siram schrieb:
> I am having issues installing Yi with the GTK frontend.
The gtk frontend has been replaced by the pango frontend. It depends on
gtk2hs likewise. On installation, pass -fpango to Setup.hs to make sure
that the frontend will get installed, or to be told what it doesn't find.
Kalman
------------------------------
Message: 7
Date: Sat, 18 Apr 2009 09:56:36 +0200
From: Kalman Noel <[email protected]>
Subject: Re: [Haskell-beginners] Partial Loading and Debugging with
GHCI
To: aditya siram <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
aditya siram schrieb:
> I would then have to comment out 'bad', reload the program and query output
> types to my hearts content. This is fine for a small program, but when I
> have functions are downriver from 'bad', it gets extremely cumbersome. Is
> there a way to load a file such that functions that compile stay loaded in
> the interpreter even if something else fails?
You can identify the offensive functions and write, in your example,
bad :: String
-- bad = hello ++ number
bad = undefined
------------------------------
Message: 8
Date: Mon, 20 Apr 2009 22:58:09 +0200 (CEST)
From: Erik Quaeghebeur <[email protected]>
Subject: [Haskell-beginners] problem cabal install'ing hmatrix
To: [email protected]
Message-ID: <alpine.lnx.2.00.0904202255240.25...@ybpnyubfg>
Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII
$ cabal install hmatrix
Resolving dependencies...
Configuring hmatrix-0.5.1.1...
Preprocessing library hmatrix-0.5.1.1...
running dist/build/Numeric/GSL/Special/Internal_hsc_make failed
command was: dist/build/Numeric/GSL/Special/Internal_hsc_make
>dist/build/Numeric/GSL/Special/Internal.hs
cabal: Error: some packages failed to install:
hmatrix-0.5.1.1 failed during the building phase. The exception was:
exit: ExitFailure 1
What should I do to diagnose/resolve this problem?
I'm on Gentoo/amd64 and have also posted this question in the gentoo
forums.
TIA for any help and pointers,
Erik
------------------------------
Message: 9
Date: Mon, 20 Apr 2009 18:26:35 -0500
From: Ian Duncan <[email protected]>
Subject: [Haskell-beginners] Parsec 3.0 problems
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello everyone,
I have the simple applicative parser combinator:
parseLabel = Label <$> (between spaces (char ':') (many1 alphaNum))
This gives me the error:
No instance for (Stream s m Char)
arising from a use of `spaces' at tree.hs:18:32-37
Possible fix: add an instance declaration for (Stream s m Char)
In the first argument of `between', namely `spaces'
In the second argument of `(<$>)', namely
`(between spaces (char ':') (many1 alphaNum))'
In the expression:
Label <$> (between spaces (char ':') (many1 alphaNum))
When I test this function in ghci, I have no problems, yet whenever I try to
open it in a file it fails. What am I doing wrong?
For those who are curious, Label is a data constructor in the following data
type:
data Loc = Label String
| Addr Int
deriving Show
Thanks!
Ian Duncan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090420/a63cee98/attachment.htm
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 10, Issue 18
*****************************************