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. Can I lift this interestingly typed function into a Maybe?
(Simon Peter Nicholls)
2. Re: Can I lift this interestingly typed function into a
Maybe? (Kim-Ee Yeoh)
3. Re: Can I lift this interestingly typed function into a
Maybe? (Simon Peter Nicholls)
4. Reply-To fixed for this mailing list (Kim-Ee Yeoh)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Jan 2013 15:56:47 +0100
From: Simon Peter Nicholls <[email protected]>
Subject: [Haskell-beginners] Can I lift this interestingly typed
function into a Maybe?
To: [email protected]
Message-ID:
<caeacoj+vgy70nienjsehbslqwiw56u0tviavf3vyn9-2mfh...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi all,
My issue is generic Haskell use, but I should provide the specific
background. I have some Snap code:
eres <- eitherWithDB $ DB.findOne (DB.select [] "someCollection")
let maybeVal = either (error "Mongoed") (maybe Nothing fromBson) eres
and this works so that "maybeVal" will be of type Maybe MyType. "eres" is
either a MongoDB Failure, or a Maybe Document (I find one document, or not).
I'd like to convert this Maybe Document to a Maybe MyType without unpacking
and repacking the Maybe. Is this possible?
The fromBson function, that converts from a Document to an end user type,
confuses me due to it's type:
fromBson ::
Monad<http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Control-Monad.html#t:Monad>
m
=>
Document<http://hackage.haskell.org/packages/archive/bson/0.1.7/doc/html/Data-Bson.html#t:Document>
->
m a
Thanks,
Si
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130124/9f21e3af/attachment-0001.htm>
------------------------------
Message: 2
Date: Thu, 24 Jan 2013 22:24:55 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] Can I lift this interestingly typed
function into a Maybe?
To: Simon Peter Nicholls <[email protected]>
Cc: [email protected]
Message-ID:
<CAPY+ZdSLqAnC_rhpcaQrCwFx6thsYiq=gvbrf_0ukhg151m...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Thu, Jan 24, 2013 at 9:56 PM, Simon Peter Nicholls
<[email protected]>wrote:
> I'd like to convert this Maybe Document to a Maybe MyType without
> unpacking and repacking the Maybe. Is this possible?
>
That would be exactly
fmap :: (Document -> MyType) -> (Maybe Document -> Maybe MyType)
where I've instantiated the type variables for your use case.
> The fromBson function, that converts from a Document to an end user type,
> confuses me due to it's type:
>
> fromBson ::
> Monad<http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Control-Monad.html#t:Monad>
> m
> =>
> Document<http://hackage.haskell.org/packages/archive/bson/0.1.7/doc/html/Data-Bson.html#t:Document>
> ->
> m a
>
All the small, single letters are type variables. Because they are
implicitly universally quantified; you, the caller, gets to specify what
you want them to be. Written out in full, it's actually
fromBson :: forall (m :: * -> *), a. Monad m => Document -> m a
Here, again specializing for your use case, fromBson probably needs to be
of type
fromBson :: Document -> Maybe MyType
So if you have a rightEres :: Maybe Document
then
fmap fromBson rightEres :: Maybe (Maybe MyType)
which you could then
join $ fmap fromBson rightEres :: Maybe MyType
What you're really after is the more idiomatic
rightEres >>= fromBson :: Maybe MyType
HTH,
-- Kim-Ee
>
> Thanks,
> Si
>
>
> _______________________________________________
> 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/20130124/b0867d76/attachment-0001.htm>
------------------------------
Message: 3
Date: Thu, 24 Jan 2013 16:37:30 +0100
From: Simon Peter Nicholls <[email protected]>
Subject: Re: [Haskell-beginners] Can I lift this interestingly typed
function into a Maybe?
To: Kim-Ee Yeoh <[email protected]>
Cc: [email protected]
Message-ID:
<CAEaCoJK=nuej9nkwueakd6iyub7emxobf5uk4y8txetaajr...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Ahhh, thank you. The following works:
let meal = either (error "Mongoed") (>>= fromBson) eres
On Thu, Jan 24, 2013 at 4:24 PM, Kim-Ee Yeoh <[email protected]> wrote:
> On Thu, Jan 24, 2013 at 9:56 PM, Simon Peter Nicholls <
> [email protected]> wrote:
>
>> I'd like to convert this Maybe Document to a Maybe MyType without
>> unpacking and repacking the Maybe. Is this possible?
>>
>
> That would be exactly
>
> fmap :: (Document -> MyType) -> (Maybe Document -> Maybe MyType)
>
> where I've instantiated the type variables for your use case.
>
>
>> The fromBson function, that converts from a Document to an end user type,
>> confuses me due to it's type:
>>
>> fromBson ::
>> Monad<http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Control-Monad.html#t:Monad>
>> m
>> =>
>> Document<http://hackage.haskell.org/packages/archive/bson/0.1.7/doc/html/Data-Bson.html#t:Document>
>> ->
>> m a
>>
>
> All the small, single letters are type variables. Because they are
> implicitly universally quantified; you, the caller, gets to specify what
> you want them to be. Written out in full, it's actually
>
> fromBson :: forall (m :: * -> *), a. Monad m => Document -> m a
>
> Here, again specializing for your use case, fromBson probably needs to be
> of type
>
> fromBson :: Document -> Maybe MyType
>
> So if you have a rightEres :: Maybe Document
>
> then
>
> fmap fromBson rightEres :: Maybe (Maybe MyType)
>
> which you could then
>
> join $ fmap fromBson rightEres :: Maybe MyType
>
> What you're really after is the more idiomatic
>
> rightEres >>= fromBson :: Maybe MyType
>
> HTH,
> -- Kim-Ee
>
>
>
>
>>
>> Thanks,
>> Si
>>
>>
>> _______________________________________________
>> 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/20130124/6597a8f6/attachment-0001.htm>
------------------------------
Message: 4
Date: Fri, 25 Jan 2013 16:43:04 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: [Haskell-beginners] Reply-To fixed for this mailing list
To: Miguel Negrao <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<CAPY+ZdSNkFjsrdrcoAGhK4vH=n6m4sk8zuh7hly7ermcrxs...@mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"
Hey Miguel,
Just got word from Benjamin (list owner) that he's fixed it.
-- Kim-Ee
On Mon, Jan 21, 2013 at 3:26 AM, Kim-Ee Yeoh <[email protected]> wrote:
> On Mon, Jan 21, 2013 at 3:07 AM, Miguel Negrao <
> [email protected]> wrote:
>
>> A 20/01/2013, ?s 05:50, Kim-Ee Yeoh escreveu:
>> > p.s. Everyone, please "Reply to All" to make sure your email gets to
>> the list reflector at haskell.org. Otherwise your responses are private
>> to Martin and you lose out on the aspect of community.
>>
>> I don?t understand: why can?t this mailing automatically set the
>> ?reply-to? field to [email protected] ? A lot of the other mailing
>> lists that I?m subscribed to do that... Is it a conscious decision or a
>> technical limitation ?
>>
>
> Excellent question! I believe we're on mailman software and the list admin
> is Benjamin Russell: [email protected] or [email protected]
>
> I've cc'ed both to see if we can get a response from him.
>
> It does look as if it's merely a config option:
>
> http://ccit.mines.edu/Mailman-FAQ#25
>
> -- Kim-Ee
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130125/7a4bd022/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 55, Issue 26
*****************************************