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: Re: Boilerplate Code (Kyle Murphy)
2. Re: Re: Boilerplate Code (Kyle Murphy)
3. Re: Re: Boilerplate Code (Ozgur Akgun)
----------------------------------------------------------------------
Message: 1
Date: Tue, 3 Aug 2010 14:42:03 -0400
From: Kyle Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Re: Boilerplate Code
To: Alex Rozenshteyn <[email protected]>
Cc: Christian Maeder <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Actually looking at the original question I'm not sure my code does what was
intended. I was looking at does some type (a b) == (a c), which wasn't
exactly the question. Oh well, back to the drawing board.
-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.
On Tue, Aug 3, 2010 at 14:38, Kyle Murphy <[email protected]> wrote:
> Less of a dirty dirty hack (requires that SchemeVal be an instance of
> Typeable):
>
> import Data.Typeable
> import Data.Maybe
>
> typeChecker :: (Typeable a, Typeable b) => a -> b -> Bool
> typeChecker a b = f a == f b
> where
> f :: (Typeable a) => a -> Maybe TypeRep
> f = listToMaybe . typeRepArgs . typeOf
>
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
>
> On Tue, Aug 3, 2010 at 13:51, Alex Rozenshteyn <[email protected]>wrote:
>
>> That is a dirty, dirty hack.
>>
>>
>> On Tue, Aug 3, 2010 at 8:45 PM, Christian Maeder <
>> [email protected]> wrote:
>>
>>> Matt Andrew schrieb:
>>> > Hi all,
>>> >
>>> > I am in the process of writing a Scheme interpreter/compiler in Haskell
>>> as my first serious project after learning the basics of Haskell. The goal
>>> is to really get a feel for Haskell. I am trying to accomplish this as much
>>> as I can on my own, but am referring to Jonathan Tang's 'Write Yourself a
>>> Scheme in 48 hours' whenever I get really stuck.
>>> >
>>> > I have a question regarding a pattern that I have found within my code
>>> for which I cannot seem to find an abstraction.
>>> >
>>> > I am implementing some of the primitive Scheme type-checker functions
>>> with the following code:
>>> >
>>> > numberP :: SchemeVal -> SchemeVal
>>> > numberP (Number _) = Bool True
>>> > numberP _ = Bool False
>>> >
>>> > boolP :: SchemeVal -> SchemeVal
>>> > boolP (Bool _) = Bool True
>>> > boolP _ = Bool False
>>> >
>>> > symbolP :: SchemeVal -> SchemeVal
>>> > symbolP (Atom _) = Bool True
>>> > symbolP _ = Bool False
>>> >
>>> > This is a pattern that I could easily provide an abstraction for with a
>>> Lisp macro, but I'm having trouble discovering if/how it's possible to do so
>>> elegantly in Haskell. The closest (but obviously incorrect) code to what I'm
>>> trying to accomplish would be:
>>> >
>>> > typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
>>> > typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
>>> >
>>> > I understand this code drastically misunderstands how pattern matching
>>> works, but (hopefully) it expresses what I'm trying to accomplish. Anyone
>>> have any suggestions?
>>>
>>> typeChecker s1 s2 = let f = takeWhile isAlphaNum . show in
>>> Bool $ f s1 == f s2
>>>
>>> hoping that my "f" just extracts the constructor as string.
>>>
>>> C.
>>>
>>> > I do realise that such an abstraction is barely worth it for the amount
>>> of code it will save, but this exercise is about learning the ins and outs
>>> of Haskell.
>>> >
>>> > Appreciate you taking the time to read this,
>>> >
>>> > Matt Andrew
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>>
>> --
>> () ascii ribbon campaign - against html e-mail
>> /\ www.asciiribbon.org - against proprietary attachments
>>
>> Alex R
>>
>>
>> _______________________________________________
>> 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/20100803/c98bc450/attachment-0001.html
------------------------------
Message: 2
Date: Tue, 3 Aug 2010 14:50:41 -0400
From: Kyle Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Re: Boilerplate Code
To: Alex Rozenshteyn <[email protected]>
Cc: Christian Maeder <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
I was close, this actually does what was asked:
import Data.Data
typeChecker :: (Typeable a, Typeable b, Data a, Data b) => a -> b -> Bool
typeChecker a b = toConstr a == toConstr b
-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.
On Tue, Aug 3, 2010 at 14:42, Kyle Murphy <[email protected]> wrote:
> Actually looking at the original question I'm not sure my code does what
> was intended. I was looking at does some type (a b) == (a c), which wasn't
> exactly the question. Oh well, back to the drawing board.
>
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
> On Tue, Aug 3, 2010 at 14:38, Kyle Murphy <[email protected]> wrote:
>
>> Less of a dirty dirty hack (requires that SchemeVal be an instance of
>> Typeable):
>>
>> import Data.Typeable
>> import Data.Maybe
>>
>> typeChecker :: (Typeable a, Typeable b) => a -> b -> Bool
>> typeChecker a b = f a == f b
>> where
>> f :: (Typeable a) => a -> Maybe TypeRep
>> f = listToMaybe . typeRepArgs . typeOf
>>
>>
>> -R. Kyle Murphy
>> --
>> Curiosity was framed, Ignorance killed the cat.
>>
>>
>>
>> On Tue, Aug 3, 2010 at 13:51, Alex Rozenshteyn <[email protected]>wrote:
>>
>>> That is a dirty, dirty hack.
>>>
>>>
>>> On Tue, Aug 3, 2010 at 8:45 PM, Christian Maeder <
>>> [email protected]> wrote:
>>>
>>>> Matt Andrew schrieb:
>>>> > Hi all,
>>>> >
>>>> > I am in the process of writing a Scheme interpreter/compiler in
>>>> Haskell as my first serious project after learning the basics of Haskell.
>>>> The goal is to really get a feel for Haskell. I am trying to accomplish
>>>> this
>>>> as much as I can on my own, but am referring to Jonathan Tang's 'Write
>>>> Yourself a Scheme in 48 hours' whenever I get really stuck.
>>>> >
>>>> > I have a question regarding a pattern that I have found within my code
>>>> for which I cannot seem to find an abstraction.
>>>> >
>>>> > I am implementing some of the primitive Scheme type-checker functions
>>>> with the following code:
>>>> >
>>>> > numberP :: SchemeVal -> SchemeVal
>>>> > numberP (Number _) = Bool True
>>>> > numberP _ = Bool False
>>>> >
>>>> > boolP :: SchemeVal -> SchemeVal
>>>> > boolP (Bool _) = Bool True
>>>> > boolP _ = Bool False
>>>> >
>>>> > symbolP :: SchemeVal -> SchemeVal
>>>> > symbolP (Atom _) = Bool True
>>>> > symbolP _ = Bool False
>>>> >
>>>> > This is a pattern that I could easily provide an abstraction for with
>>>> a Lisp macro, but I'm having trouble discovering if/how it's possible to do
>>>> so elegantly in Haskell. The closest (but obviously incorrect) code to what
>>>> I'm trying to accomplish would be:
>>>> >
>>>> > typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
>>>> > typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
>>>> >
>>>> > I understand this code drastically misunderstands how pattern matching
>>>> works, but (hopefully) it expresses what I'm trying to accomplish. Anyone
>>>> have any suggestions?
>>>>
>>>> typeChecker s1 s2 = let f = takeWhile isAlphaNum . show in
>>>> Bool $ f s1 == f s2
>>>>
>>>> hoping that my "f" just extracts the constructor as string.
>>>>
>>>> C.
>>>>
>>>> > I do realise that such an abstraction is barely worth it for the
>>>> amount of code it will save, but this exercise is about learning the ins
>>>> and
>>>> outs of Haskell.
>>>> >
>>>> > Appreciate you taking the time to read this,
>>>> >
>>>> > Matt Andrew
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> [email protected]
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>
>>>
>>>
>>> --
>>> () ascii ribbon campaign - against html e-mail
>>> /\ www.asciiribbon.org - against proprietary attachments
>>>
>>> Alex R
>>>
>>>
>>> _______________________________________________
>>> 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/20100803/c9dde58c/attachment-0001.html
------------------------------
Message: 3
Date: Tue, 3 Aug 2010 20:01:35 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Re: Boilerplate Code
To: Kyle Murphy <[email protected]>
Cc: Christian Maeder <[email protected]>, [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Why do you need them to be Typeable? toConstr has the following type:
toConstr :: (Data a) => a -> Constr
Best,
On 3 August 2010 19:50, Kyle Murphy <[email protected]> wrote:
> I was close, this actually does what was asked:
>
> import Data.Data
>
> typeChecker :: (Typeable a, Typeable b, Data a, Data b) => a -> b -> Bool
> typeChecker a b = toConstr a == toConstr b
>
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
> On Tue, Aug 3, 2010 at 14:42, Kyle Murphy <[email protected]> wrote:
>
>> Actually looking at the original question I'm not sure my code does what
>> was intended. I was looking at does some type (a b) == (a c), which wasn't
>> exactly the question. Oh well, back to the drawing board.
>>
>>
>> -R. Kyle Murphy
>> --
>> Curiosity was framed, Ignorance killed the cat.
>>
>>
>> On Tue, Aug 3, 2010 at 14:38, Kyle Murphy <[email protected]> wrote:
>>
>>> Less of a dirty dirty hack (requires that SchemeVal be an instance of
>>> Typeable):
>>>
>>> import Data.Typeable
>>> import Data.Maybe
>>>
>>> typeChecker :: (Typeable a, Typeable b) => a -> b -> Bool
>>> typeChecker a b = f a == f b
>>> where
>>> f :: (Typeable a) => a -> Maybe TypeRep
>>> f = listToMaybe . typeRepArgs . typeOf
>>>
>>>
>>> -R. Kyle Murphy
>>> --
>>> Curiosity was framed, Ignorance killed the cat.
>>>
>>>
>>>
>>> On Tue, Aug 3, 2010 at 13:51, Alex Rozenshteyn <[email protected]>wrote:
>>>
>>>> That is a dirty, dirty hack.
>>>>
>>>>
>>>> On Tue, Aug 3, 2010 at 8:45 PM, Christian Maeder <
>>>> [email protected]> wrote:
>>>>
>>>>> Matt Andrew schrieb:
>>>>> > Hi all,
>>>>> >
>>>>> > I am in the process of writing a Scheme interpreter/compiler in
>>>>> Haskell as my first serious project after learning the basics of Haskell.
>>>>> The goal is to really get a feel for Haskell. I am trying to accomplish
>>>>> this
>>>>> as much as I can on my own, but am referring to Jonathan Tang's 'Write
>>>>> Yourself a Scheme in 48 hours' whenever I get really stuck.
>>>>> >
>>>>> > I have a question regarding a pattern that I have found within my
>>>>> code for which I cannot seem to find an abstraction.
>>>>> >
>>>>> > I am implementing some of the primitive Scheme type-checker functions
>>>>> with the following code:
>>>>> >
>>>>> > numberP :: SchemeVal -> SchemeVal
>>>>> > numberP (Number _) = Bool True
>>>>> > numberP _ = Bool False
>>>>> >
>>>>> > boolP :: SchemeVal -> SchemeVal
>>>>> > boolP (Bool _) = Bool True
>>>>> > boolP _ = Bool False
>>>>> >
>>>>> > symbolP :: SchemeVal -> SchemeVal
>>>>> > symbolP (Atom _) = Bool True
>>>>> > symbolP _ = Bool False
>>>>> >
>>>>> > This is a pattern that I could easily provide an abstraction for with
>>>>> a Lisp macro, but I'm having trouble discovering if/how it's possible to
>>>>> do
>>>>> so elegantly in Haskell. The closest (but obviously incorrect) code to
>>>>> what
>>>>> I'm trying to accomplish would be:
>>>>> >
>>>>> > typeChecker :: SchemeVal -> SchemeVal -> SchemeVal
>>>>> > typeChecker (cons _) (cons2 _) = Bool $ cons == cons2
>>>>> >
>>>>> > I understand this code drastically misunderstands how pattern
>>>>> matching works, but (hopefully) it expresses what I'm trying to
>>>>> accomplish.
>>>>> Anyone have any suggestions?
>>>>>
>>>>> typeChecker s1 s2 = let f = takeWhile isAlphaNum . show in
>>>>> Bool $ f s1 == f s2
>>>>>
>>>>> hoping that my "f" just extracts the constructor as string.
>>>>>
>>>>> C.
>>>>>
>>>>> > I do realise that such an abstraction is barely worth it for the
>>>>> amount of code it will save, but this exercise is about learning the ins
>>>>> and
>>>>> outs of Haskell.
>>>>> >
>>>>> > Appreciate you taking the time to read this,
>>>>> >
>>>>> > Matt Andrew
>>>>> _______________________________________________
>>>>> Beginners mailing list
>>>>> [email protected]
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> () ascii ribbon campaign - against html e-mail
>>>> /\ www.asciiribbon.org - against proprietary attachments
>>>>
>>>> Alex R
>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> [email protected]
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100803/e541a1ca/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 26, Issue 6
****************************************