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: Is there such a thing as a lazy monadic list?
(Elvio Toccalino)
2. Re: Question about constraints, signatures (Philippe Sismondi)
3. Re: haskell for FPGAS (David Blubaugh)
4. Typeclasses and generic types (Christopher Howard)
5. Re: Typeclasses and generic types (Arlen Cuss)
6. Re: Typeclasses and generic types (Elvio Toccalino)
----------------------------------------------------------------------
Message: 1
Date: Mon, 09 May 2011 10:29:31 -0300
From: Elvio Toccalino <[email protected]>
Subject: Re: [Haskell-beginners] Is there such a thing as a lazy
monadic list?
To: [email protected]
Message-ID: <1304947773.1589.2.camel@el-fierro>
Content-Type: text/plain; charset="UTF-8"
Couldn't this be solved with an Iteratee approach? An Enumerator
produces values from your VM, an Enumeratee checks that only enough pass
(enough to disassemble 'this' instruction) and an Iteratee chews the
memory into the final value.
I'm writing this without the time to actually develop it, I'm sorry for
not providing any examples.
On Mon, 2011-05-09 at 18:41 +1000, Arlen Cuss wrote:
> Hi all,
>
> I'm currently trying to write a very simple VM in order to learn and
> stretch my Haskell. I'm currently up against a problem.
>
> I'm using an (IOUArray Int Word32) to represent the memory of a VM
> instance. This is all fine so far, but now I'm trying to write a
> 'disassemble' function that will disassemble an instruction starting
> from a given location in memory.
>
> Ideally I could write a function that would lazily yield successive
> elements from memory, sort of like this:
>
> > readVMFrom :: VM -> Address -> IO [Word32]
> > readVMFrom v f = do
> > i <- readArray (memory v) f
> > rest <- readVMFrom v (succ f)
> > return $ i : readVMFrom v (succ f)
>
> Of course, this isn't lazy, and so happily runs off the end of memory
> each time. (I could stop that, but that's not the point!) I'm not sure
> how to lazily construct a list in IO.
>
> My next thought is to instead make a function to return an action that
> yields successive values of memory, given some start, i.e. something
> like:
>
> > readVMFrom :: VM -> Address -> IO Word32
>
> .. but I'm thinking I might have to do some StateT nonsense in order to
> actually keep track of which index we want to read next. (subtext: I
> don't know how to do that!)
>
> So I then think that perhaps I can do this by having readVMFrom return
> an action which yields a) the next value, b) the address of the next
> value (so we know how much we ate), and c) an action to yield the next
> value and action and so on, so on. I managed that this way (WARNING,
> BEGINNER HASKELL CODE FOLLOWS):
>
> > newtype RVFResult = RVFResult { getRVFResult :: (Word32, Address, IO
> RVFResult) }
> >
> > readVMFrom :: VM -> Address -> IO RVFResult
> > readVMFrom v f = do
> > i <- readArray (memory v) f
> > return $ RVFResult (i, succ f, readVMFrom v $ succ f)
>
> A function can then take an argument of type RVFResult as an indication
> it wants 1..n sequential values from memory:
>
> > disassemble :: RVFResult -> IO (Instruction, Address)
> > disassemble r = do
> > let (i, p, a) = getRVFResult r
> > case i of
> > 0x01 -> return (Push, p)
> > 0x02 -> return (Pop, p)
> > 0x03 -> return (Call, p)
> > 0x04 -> do
> > r <- a
> > let (v, p, a) = getRVFResult r
> > return (Out v, p)
>
> Here you can see how we consume an additional value by executing the
> returned action 'a'. It's damn ugly, and this almost looks like the
> place for a monad (possibly something involving StateT, though, I don't
> know!).
>
> Ideally I'd manage a lazily constructed list -- somehow I feel that's
> most "Haskelly" -- but does anyone else have any ideas? I kinda fleshed
> this last solution out as I wrote this email, so it's kinda cruddy.
>
> Cheers,
>
> Arlen
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Mon, 9 May 2011 16:47:28 -0400
From: Philippe Sismondi <[email protected]>
Subject: Re: [Haskell-beginners] Question about constraints,
signatures
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On 2011-05-09, at 4:04 AM, David Virebayre wrote:
> 2011/5/8 Philippe Sismondi <[email protected]>:
>
>> On 2011-05-06, at 12:12 PM, Brent Yorgey wrote:
>
>>> On Fri, May 06, 2011 at 11:34:47AM -0400, Philippe Sismondi wrote:
>>>> I am trying to understand the Typeclassopedia article by Brent Yorgey in
>>>> Monad.Reader. I am simultaneously working my way through Real World
>>>> Haskell, so I may be doing things a bit out of order.
>
>>>> I (more or less) understand that types and typeclasses are not the same.
>>>> But it seems to me that they do conflate in a way, if we think of types as
>>>> defined by functions on them.
>>>> So why should we not be able to write:
>
>>>> f :: Num d -> String -> Int
>
> You can have multiple class constraints, so it's not clear how you
> would write them using your syntax; how would you write :
>
> f :: (Eq d, Ord d) => d -> String -> Int ?
>
> Also, you only have to tell the class constraint once, with your syntax
>
> g :: (Num d) => d -> d -> d
>
> would become:
>
> g :: Num d -> Num d -> Num d
>
> but that syntax lets you write nonsense :
>
> h :: Num d -> Eq d -> Ord d
>
>
> David.
David:
Thanks for your input. As I have quite a distance to go with Haskell, I shall
take all these comments under advisement.
- Phil -
------------------------------
Message: 3
Date: Mon, 9 May 2011 17:43:55 -0700 (PDT)
From: David Blubaugh <[email protected]>
Subject: Re: [Haskell-beginners] haskell for FPGAS
To: Bas van Gijzel <[email protected]>, Jo?o Paulo Pizani Flor
<[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Sir,
?
Are you still out there???
?
Yes, I would be very interested in the information you would provide !!!
?
David Blubaugh
?
--- On Tue, 1/25/11, Jo?o Paulo Pizani Flor <[email protected]> wrote:
From: Jo?o Paulo Pizani Flor <[email protected]>
Subject: Re: [Haskell-beginners] haskell for FPGAS
To: "Bas van Gijzel" <[email protected]>
Cc: "David Blubaugh" <[email protected]>, [email protected]
Date: Tuesday, January 25, 2011, 1:23 PM
Hey David, I think I might be working EXACTLY with what you mean :)
I'm using ForSyDe (a Haskell DSL for High-Level hardware design) now as part of
my undergraduate thesis. I already have some VERY simple designs tested and
synthesized, if you want to take a peak just contact me and I'll be glad to
chat with you and provide all the code and tips :)
Here's the (Hackage) site for
ForSyDe:?http://hackage.haskell.org/package/ForSyDe
Good luck!
Jo?o Paulo Pizani Flor
[email protected]
Computer Science - 2007/1
Federal University of Santa Catarina - Brazil
On Mon, Jan 17, 2011 at 6:25 PM, Bas van Gijzel <[email protected]> wrote:
Well at University of Twente (Netherlands) they work a lot with Haskell/Clash
and FPGA's.?
You can look at two Master's theses written by students there:
http://essay.utwente.nl/59482/
http://essay.utwente.nl/59381/
Bas
On 17 January 2011 17:37, Tom Murphy <[email protected]> wrote:
Continuing the "Not exactly" trend, you could always ask this guy...
http://www.youtube.com/watch?v=-zEWS7P91d4
http://blog.sigfpe.com/2007/05/haskell-incarnate.html
Tom
On Sun, Jan 16, 2011 at 1:44 AM, David Blubaugh <[email protected]>
wrote:
To All,
?
?
Has anyone developed HASKELL FOR FPGA development ??
?
Thank You,
?
Daid Blubaugh
?
?
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
--
http://adoseoflogic.blogspot.com/
_______________________________________________
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/20110509/dc852092/attachment-0001.htm>
------------------------------
Message: 4
Date: Mon, 09 May 2011 19:25:15 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] Typeclasses and generic types
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I'm learning how to use typeclasses for the first time, and I tried
something like so:
[CODE]
data Point a = Point a a
getX (Point a _) = a
getY (Point _ a) = a
instance Eq Point where
(==) a b = getX a == getX b && getY a == getY b
[/CODE]
But when I try to load this in GHCI I get:
[CODE]
`Point' is not applied to enough type arguments
The first argument of `Eq' should have kind `*',
but `Point' has kind `* -> *'
In the instance declaration for `Eq Point'
[/CODE]
This seems to be saying that Eq requires a concrete argument, which I
suppose I can understand.
I can fix this by changing "data Point a = Point a a" into "data Point =
Point Int Int" or something like that, but that seems kind of lame: what
if I want to leave my Point type more generic? (Maybe sometimes I'll
need a Point Int, and other times I'll need a Point Float, or some other
weird combination I haven't thought of yet.)
Instead of changing the "data" declaration, can I change the "instance"
declaration somehow so that it just defines an instance for a particular
Point sub-type? I tried some variations like "instance Eq (Point Float)"
but I haven't been able to come up with anything yet that satisfies the
compiler.
--
frigidcode.com
theologia.indicium.us
------------------------------
Message: 5
Date: Tue, 10 May 2011 13:35:26 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] Typeclasses and generic types
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <1304998526.3606.1.camel@azayaka>
Content-Type: text/plain; charset="utf-8"
Hi Christopher,
Try this instead:
instance Eq (Point a) where
..
Eq needs to take a type of kind `*', meaning the type itself doesn't
have any type variables left. `Point' by itself is a type 'constructor',
if you will, that needs another type to complete it (thus you can
imagine it's like a 'type function' of kind `* -> *', meaning you need
to give one type (`*') to yield a type `*').
You can just use `a' (or whatever) to represent any type filled in
there, however.
HTH!
Arlen
On Mon, 2011-05-09 at 19:25 -0800, Christopher Howard wrote:
> I'm learning how to use typeclasses for the first time, and I tried
> something like so:
>
> [CODE]
> data Point a = Point a a
>
> getX (Point a _) = a
> getY (Point _ a) = a
>
> instance Eq Point where
> (==) a b = getX a == getX b && getY a == getY b
> [/CODE]
>
> But when I try to load this in GHCI I get:
>
> [CODE]
> `Point' is not applied to enough type arguments
> The first argument of `Eq' should have kind `*',
> but `Point' has kind `* -> *'
> In the instance declaration for `Eq Point'
> [/CODE]
>
> This seems to be saying that Eq requires a concrete argument, which I
> suppose I can understand.
>
> I can fix this by changing "data Point a = Point a a" into "data Point =
> Point Int Int" or something like that, but that seems kind of lame: what
> if I want to leave my Point type more generic? (Maybe sometimes I'll
> need a Point Int, and other times I'll need a Point Float, or some other
> weird combination I haven't thought of yet.)
>
> Instead of changing the "data" declaration, can I change the "instance"
> declaration somehow so that it just defines an instance for a particular
> Point sub-type? I tried some variations like "instance Eq (Point Float)"
> but I haven't been able to come up with anything yet that satisfies the
> compiler.
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110510/0849ad43/attachment-0001.pgp>
------------------------------
Message: 6
Date: Tue, 10 May 2011 00:44:20 -0300
From: Elvio Toccalino <[email protected]>
Subject: Re: [Haskell-beginners] Typeclasses and generic types
To: [email protected]
Message-ID: <1304999063.1640.4.camel@el-fierro>
Content-Type: text/plain; charset="UTF-8"
One further addendum to the answer provided by Arlen:
Notice that
instance Eq Point where
(==) a b = getX a == getX b && getY a == getY b
is defining equality between 'Point a' (as well pointed out by Arlen),
but it does so in terms of equality test between 'a'... but there's no
declaration in your code stating that 'a' can be equated.
This all boils does to the following instance declaration:
instance Eq a => Eq (Point a) where ...
which reads nicely :)
On Tue, 2011-05-10 at 13:35 +1000, Arlen Cuss wrote:
> Hi Christopher,
>
> Try this instead:
>
> instance Eq (Point a) where
> ..
>
> Eq needs to take a type of kind `*', meaning the type itself doesn't
> have any type variables left. `Point' by itself is a type 'constructor',
> if you will, that needs another type to complete it (thus you can
> imagine it's like a 'type function' of kind `* -> *', meaning you need
> to give one type (`*') to yield a type `*').
>
> You can just use `a' (or whatever) to represent any type filled in
> there, however.
>
> HTH!
>
> Arlen
>
> On Mon, 2011-05-09 at 19:25 -0800, Christopher Howard wrote:
> > I'm learning how to use typeclasses for the first time, and I tried
> > something like so:
> >
> > [CODE]
> > data Point a = Point a a
> >
> > getX (Point a _) = a
> > getY (Point _ a) = a
> >
> > instance Eq Point where
> > (==) a b = getX a == getX b && getY a == getY b
> > [/CODE]
> >
> > But when I try to load this in GHCI I get:
> >
> > [CODE]
> > `Point' is not applied to enough type arguments
> > The first argument of `Eq' should have kind `*',
> > but `Point' has kind `* -> *'
> > In the instance declaration for `Eq Point'
> > [/CODE]
> >
> > This seems to be saying that Eq requires a concrete argument, which I
> > suppose I can understand.
> >
> > I can fix this by changing "data Point a = Point a a" into "data Point =
> > Point Int Int" or something like that, but that seems kind of lame: what
> > if I want to leave my Point type more generic? (Maybe sometimes I'll
> > need a Point Int, and other times I'll need a Point Float, or some other
> > weird combination I haven't thought of yet.)
> >
> > Instead of changing the "data" declaration, can I change the "instance"
> > declaration somehow so that it just defines an instance for a particular
> > Point sub-type? I tried some variations like "instance Eq (Point Float)"
> > but I haven't been able to come up with anything yet that satisfies the
> > compiler.
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 16
*****************************************