I have a -> f a. How to get m a -> f m a ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Baa
Reply | Threaded
Open this post in threaded view
|

I have a -> f a. How to get m a -> f m a ?

Baa
Hello List!

I have function a -> IO a. How to get function:

  Maybe a -> IO (Maybe a)  ?

I found in Haskell mails archive such thing:

   class IFunctor f where
     imap :: Idiom i => (s -> i t) -> f s -> i (f t)

which looks similar, but I didn't find any helpfull instances of
`IFunctor` class in its package (and unfortunately I don't know what are
the indexed types: IMonad, IFunctor, etc). Sure, there is the primitive
solution like:

   myfunc :: a -> IO a
   ...
   f x = case x of Nothing -> return Nothing
                   Just x' -> Just <$> myfunc x'

but more interesting is to know more standard and Haskelish solution
(like lift's, etc). May be I miss something very obvious..

===
Best regards, Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: I have a -> f a. How to get m a -> f m a ?

Imants Cekusins
> I have function a -> IO a. How to get function:
>  Maybe a -> IO (Maybe a)  ?

Will mapM work:

On 4 September 2017 at 15:06, Baa <[hidden email]> wrote:
Hello List!

I have function a -> IO a. How to get function:

  Maybe a -> IO (Maybe a)  ?

I found in Haskell mails archive such thing:

   class IFunctor f where
     imap :: Idiom i => (s -> i t) -> f s -> i (f t)

which looks similar, but I didn't find any helpfull instances of
`IFunctor` class in its package (and unfortunately I don't know what are
the indexed types: IMonad, IFunctor, etc). Sure, there is the primitive
solution like:

   myfunc :: a -> IO a
   ...
   f x = case x of Nothing -> return Nothing
                   Just x' -> Just <$> myfunc x'

but more interesting is to know more standard and Haskelish solution
(like lift's, etc). May be I miss something very obvious..

===
Best regards, Paul
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Baa
Reply | Threaded
Open this post in threaded view
|

Re: I have a -> f a. How to get m a -> f m a ?

Baa
Hello, Imants! Exactly :)
Thanks!

> > I have function a -> IO a. How to get function:
> >  Maybe a -> IO (Maybe a)  ?  
>
> Will mapM work:
>
> http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Traversable.html#v:mapM
>
> ?
>
>
>
> On 4 September 2017 at 15:06, Baa <[hidden email]> wrote:
>
> > Hello List!
> >
> > I have function a -> IO a. How to get function:
> >
> >   Maybe a -> IO (Maybe a)  ?
> >
> > I found in Haskell mails archive such thing:
> >
> >    class IFunctor f where
> >      imap :: Idiom i => (s -> i t) -> f s -> i (f t)
> >
> > which looks similar, but I didn't find any helpfull instances of
> > `IFunctor` class in its package (and unfortunately I don't know
> > what are the indexed types: IMonad, IFunctor, etc). Sure, there is
> > the primitive solution like:
> >
> >    myfunc :: a -> IO a
> >    ...
> >    f x = case x of Nothing -> return Nothing
> >                    Just x' -> Just <$> myfunc x'
> >
> > but more interesting is to know more standard and Haskelish solution
> > (like lift's, etc). May be I miss something very obvious..
> >
> > ===
> > Best regards, Paul
> > _______________________________________________
> > Beginners mailing list
> > [hidden email]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> >  

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners