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. problems with GADTs (Michael Litchard)
2. Re: Re: randomize the order of a list (John Dorsey)
3. Convert bits to bytes (Alec Benzer)
4. Re: Convert bits to bytes (David Virebayre)
5. Re: Convert bits to bytes (David Virebayre)
6. Re: Convert bits to bytes (David Virebayre)
7. R?f. : [Haskell-beginners] problems with GADTs
([email protected])
8. Missing or recursive dependencies (Lyndon Maydwell)
9. Re: Missing or recursive dependencies (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Wed, 1 Sep 2010 12:05:41 -0700
From: Michael Litchard <[email protected]>
Subject: [Haskell-beginners] problems with GADTs
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I'm learnined how to use GADTs, but for the moment I'm stuck on the
following problem.
some context first
> newtype Cost = Cost Int
> newtype ID = ID Int
> newtype Student = Student String
> newtype Activity = Activity String
> data Table k v = PopTable
> { tableName :: String
> , tableList :: [(k, v)]
> } deriving (Show, Read)
> type Students = Table ID Student
> type ActivityCosts = Table Activity Cost
> type StudentActivities = Table Activity ID
I want to do something like this
> loaders = [("students", loadStudentIDs), ("costs", loadActivityCosts),
> ("activities", loadStudentActivities)]
But I can't have list with multiple types. Okay so ski (from #haskell)
suggested I use a GADT. This is new territory for me. Here's what it
looks like right now.
data ProgramName :: * -> *
where
PNStudents :: ProgramName Students
PNCosts :: ProgramName ActivityCosts
PNActivities :: ProgramName StudentActivities
Now I should be able to use this to define a data structure called
"loaders" that contains three tuples ("students", loadStudentIDs),
("costs", loadActivityCosts), and ("activities",
loadStudentActivities).
So, what would "loaders" look like? I've done some reading but it's
not sunk in yet.
------------------------------
Message: 2
Date: Wed, 1 Sep 2010 17:59:57 -0400
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] Re: randomize the order of a list
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Gabriel Scherer wrote:
>> Thanks for the link apfelmus, it's fairly interesting. The key to
>> making it work is the weighting of lists during merging based on their
>> lengths. I wonder if other sort algorithm can be adapted in such a
>> way, while preserving uniformity. Quicksort for example : is it enough
>> to choose the result position of the pivot randomly, and then placing
>> elements on either side with a probability of 1/2 ?
to which Heinrich Apfelmus answered:
> Interesting question! Adapting quick sort is not that easy, though.
>
> First, you can skip choosing the pivot position because it is already
> entailed by the choices of elements left and right to it.
I don't think this is true...
> Second, probability 1/2 won't work, it doesn't give a uniform
> distribution.
... because of this.
In fact, it appears to me that the proposed modification to quicksort is
uniform and simple. Why do you think otherwise?
Cheers,
John
------------------------------
Message: 3
Date: Thu, 2 Sep 2010 00:45:08 -0400
From: Alec Benzer <[email protected]>
Subject: [Haskell-beginners] Convert bits to bytes
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
What's the quickest/the best/a way of converting a series of bits into
bytes? Ie, converting a [Bool] to a [Word8]. So if I had replicate 8 True ++
replicate 8 False :: [Bool], it would spit out [255,0] :: [Word8].
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100901/04ea7c3a/attachment-0001.html
------------------------------
Message: 4
Date: Thu, 2 Sep 2010 08:56:12 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Convert bits to bytes
To: Alec Benzer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
2010/9/2 Alec Benzer <[email protected]>:
> What's the quickest/the best/a way of converting a series of bits into
> bytes? Ie, converting a [Bool] to a [Word8]. So if I had replicate 8 True ++
> replicate 8 False :: [Bool], it would spit out [255,0] :: [Word8].
Simple way :
l = [False,False,False,True,False,False,True]
foldl' (\a b -> a*2 + if b then 1 else 0) 0 l
------------------------------
Message: 5
Date: Thu, 2 Sep 2010 09:07:20 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Convert bits to bytes
To: Alec Benzer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
2010/9/2 David Virebayre <[email protected]>:
> Simple way :
>
> l = [False,False,False,True,False,False,True]
> foldl' (\a b -> a*2 + if b then 1 else 0) 0 l
Oh sorry I answered too quickly and didn't see the list can have more
than 8 bits.
chunk :: [Bool] -> [[ Bool ]]
chunk [] = []
chunk l = a : chunk b
where (a,b) = splitAt 8 l
conv1 = foldl' (\a b -> a*2 + if b then 1 else 0) 0
convlist = map conv1 . chunk
test = convlist (replicate 8 True ++ replicate 8 False :: [Bool] )
------------------------------
Message: 6
Date: Thu, 2 Sep 2010 09:18:07 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] Convert bits to bytes
To: Alec Benzer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
I could have been a bit more verbose.
The way I see it, since you have an arbitrary long list of 'bits' that
you want to convert into bytes, the first thing to do is to group this
list into sublists of 8 bits.
That's what chunk does: it splits the list at the 8th element, and
recursively does it for the rest of the list, until the list is empty.
One problem with that is that if the length of the list isn't a
multiple of 8, then the last byte might be incorrect.
> chunk :: [Bool] -> [[ Bool ]]
> chunk [] = []
> chunk l = a : chunk b
> Â where (a,b) Â = splitAt 8 l
This one converts a list of 'bits' into a number. The head of the list
is assumed to be the most significant bit :
> conv1 = foldl' (\a b -> a*2 + if b then 1 else 0) 0
if we want the head of the list to be the least significant bit, then
you can convert with foldr :
> conv1' = foldr (\b a -> a*2 + if b then 1 else 0) 0
Now converting the whole list is just a matter converting the whole
list in groups, then converting each group :
> convlist = map conv1 . chunk
>
> test = convlist (replicate 8 True ++ replicate 8 False :: [Bool] )
David.
------------------------------
Message: 7
Date: Thu, 2 Sep 2010 11:16:15 +0200
From: [email protected]
Subject: R?f. : [Haskell-beginners] problems with GADTs
To: Michael Litchard <[email protected]>
Cc: [email protected]
Message-ID:
<of01cbe1ac.481e3a75-onc1257792.0030fc6e-c1257792.0032e...@mpsa.com>
Content-Type: text/plain; charset=ISO-8859-1
Hello,
I'm beginner too but i will try to respond.
I would do this like that:
> type Cost = Int
> type ID = Int
> type Student = String
> type Activity = String
> data Table k v = PopTable
> { tableName :: String
> , tableList :: [(k, v)]
> } deriving (Show, Read)
> type Students = Table ID Student
> type ActivityCosts = Table Activity Cost
> type StudentActivities = Table Activity ID
> loaders :: [ProgramName]
> loaders = [CStudents $ PopTable "students" loadStudentIDs, CActivityCosts
$ PopTable "costs" loadActivityCosts]
> data ProgramName = CStudents Students
> | CActivityCosts ActivityCosts
> | CStudentActivities StudentActivities
> loadStudentIDs :: [(ID, Student)]
> loadStudentIDs = [(1, "marcel"), (2, "alphonse")]
> loadActivityCosts :: [(Activity, Cost)]
> loadActivityCosts = [("work", 10)]
There is no need for a GATD.
All you need here, is to hide your different types into one named
ProgramName.
Once this is done, you can have a list of ProgramName.
In the ProgramName datatype, you see different contructors, which allow you
to contruct a ProgramName.
In GHCI:
> :t CStudents
CStudents :: Students -> ProgramName
Cheers,
Corentin
Michael Litchard
<mich...@schmong
.org> Pour
Envoyé par : [email protected]
beginners-bounce cc
[email protected]
Objet
[Haskell-beginners] problems with
02/09/2010 01:11 GADTs
I'm learnined how to use GADTs, but for the moment I'm stuck on the
following problem.
some context first
> newtype Cost = Cost Int
> newtype ID = ID Int
> newtype Student = Student String
> newtype Activity = Activity String
> data Table k v = PopTable
> { tableName :: String
> , tableList :: [(k, v)]
> } deriving (Show, Read)
> type Students = Table ID Student
> type ActivityCosts = Table Activity Cost
> type StudentActivities = Table Activity ID
I want to do something like this
> loaders = [("students", loadStudentIDs), ("costs", loadActivityCosts),
("activities", loadStudentActivities)]
But I can't have list with multiple types. Okay so ski (from #haskell)
suggested I use a GADT. This is new territory for me. Here's what it
looks like right now.
data ProgramName :: * -> *
where
PNStudents :: ProgramName Students
PNCosts :: ProgramName ActivityCosts
PNActivities :: ProgramName StudentActivities
Now I should be able to use this to define a data structure called
"loaders" that contains three tuples ("students", loadStudentIDs),
("costs", loadActivityCosts), and ("activities",
loadStudentActivities).
So, what would "loaders" look like? I've done some reading but it's
not sunk in yet.
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 8
Date: Thu, 2 Sep 2010 17:31:01 +0800
From: Lyndon Maydwell <[email protected]>
Subject: [Haskell-beginners] Missing or recursive dependencies
To: Biginners Haskell Mailinglist <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Hi beginners.
I'm getting an odd problem quite a lot recently:
ghc -fglasgow-exts --make -O2 -W X.hs -v -o X
package Cabal-1.8.0.6-ec9be469687b5a514f4b7e8e2b8343c7 is shadowed by
package Cabal-1.8.0.6-c995b90190c27e1dfa2ab3d5434fabef
package QuickCheck-2.1.1.1-c7435cb0d5b5de72fe9540c48335606d is
unusable due to missing or recursive dependencies:
ghc-6.12.3-66a382195c8a71849653439b67021fd1
package bin-package-db-0.0.0.0-0dffb74a73bb78b5dc02ca941bbcbea0 is
unusable due to missing or recursive dependencies:
Cabal-1.8.0.6-ec9be469687b5a514f4b7e8e2b8343c7
package category-extras-0.53.5-ee54cd5c810a6c004a1b7a276d0e0076 is
unusable due to missing or recursive dependencies:
ghc-6.12.3-66a382195c8a71849653439b67021fd1
package comonad-random-0.1.2-897a5da683d269c3b2db3e03ac43279b is
unusable due to missing or recursive dependencies:
category-extras-0.53.5-ee54cd5c810a6c004a1b7a276d0e0076
...
I've asked on irc, and the consensus is that something is very wrong,
however we weren't able to diagnose the cause. It would probably be
worth looking at on-list for future reference.
Does anyone have any ideas?
------------------------------
Message: 9
Date: Thu, 2 Sep 2010 11:44:38 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Missing or recursive dependencies
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Thursday 02 September 2010 11:31:01, Lyndon Maydwell wrote:
> Hi beginners.
>
> I'm getting an odd problem quite a lot recently:
>
> ghc -fglasgow-exts --make -O2 -W X.hs -v -o X
>
> package Cabal-1.8.0.6-ec9be469687b5a514f4b7e8e2b8343c7 is shadowed by
> package Cabal-1.8.0.6-c995b90190c27e1dfa2ab3d5434fabef
You have two versions of Cabal-1.8.0.6, probably you should unregister the
one in the user-db.
Anyway, run ghc-pkg check first. Fix what that reports as broken by
unregistering/reinstalling.
Since what is shown below all directly or indirectly traces to ghc-6.12.3,
which depends on Cabal-1.8.0.6, your two versions of that are probably the
root cause, so I'd start with Cabal.
> package QuickCheck-2.1.1.1-c7435cb0d5b5de72fe9540c48335606d is
> unusable due to missing or recursive dependencies:
> ghc-6.12.3-66a382195c8a71849653439b67021fd1
> package bin-package-db-0.0.0.0-0dffb74a73bb78b5dc02ca941bbcbea0 is
> unusable due to missing or recursive dependencies:
> Cabal-1.8.0.6-ec9be469687b5a514f4b7e8e2b8343c7
> package category-extras-0.53.5-ee54cd5c810a6c004a1b7a276d0e0076 is
> unusable due to missing or recursive dependencies:
> ghc-6.12.3-66a382195c8a71849653439b67021fd1
> package comonad-random-0.1.2-897a5da683d269c3b2db3e03ac43279b is
> unusable due to missing or recursive dependencies:
> category-extras-0.53.5-ee54cd5c810a6c004a1b7a276d0e0076
> ...
>
> I've asked on irc, and the consensus is that something is very wrong,
> however we weren't able to diagnose the cause. It would probably be
> worth looking at on-list for future reference.
>
> Does anyone have any ideas?
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 27, Issue 3
****************************************