Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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.  Ambiguous type of WriterT result I am not using (Martin Vlk)
   2. Re:  Ambiguous type of WriterT result I am not    using
      (David McBride)
   3. Re:  Ambiguous type of WriterT result I am not    using (Kim-Ee Yeoh)
   4.  RDF with Haskell (Jeon-Young Kang)


----------------------------------------------------------------------

Message: 1
Date: Fri, 20 Nov 2015 12:14:25 +0000
From: Martin Vlk <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Ambiguous type of WriterT result I am not
        using
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Hi I have two functions, foldrEntries and foldrEntriesW, where the
latter is a WriterT version of the former. Here are the type signatures:

foldrEntries :: (Entry -> a -> a) ->
                a ->
                (String -> a) ->
                Entries ->
                a

foldrEntriesW :: (Monoid w, Monad m) =>
                 (Entry -> a -> WriterT w m a) ->
                 WriterT w m a ->
                 (String -> WriterT w m a) ->
                 Entries ->
                 WriterT w m a

I want to implement foldrEntries in terms of foldrEntriesW using the
Identity monad and ignore/not use the writer result. I am doing this in
order to reuse the foldrEntriesW implementation and avoid code duplication.

This is what I have so far:
http://lpaste.net/145641

But the compiler complains about ambiguous type for the writer reult I
am ignoring (message in the above lpaste).

Normally I think the way around this is to provide explicit type
annotation for "foldIt", but in this case the result type depends on the
type of "a" in foldrEntries type and I don't know how to express this
and make the compiler happy.

(I was able to make it work by calling "tell ()", basically writing a
dummy value, which lets compiler know what the type is, but this is not
so good - I don't want to make artificial function calls like this.)

Can anybody help me with that?

Many Thanks
Martin


------------------------------

Message: 2
Date: Fri, 20 Nov 2015 10:46:38 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Ambiguous type of WriterT result I am
        not     using
Message-ID:
        <CAN+Tr43qOs69yab3=-Cgm7AM-b2nj+fYo=qf8b_+-uvkbfg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The problem is in your string -> WriterT w m a.  It needs to know what the
w is.  It knows its a monoid but doesn't know anything else about it.  The
simplest thing is to just tell it what it is.

foldrEntries :: (Entry -> a -> a) -> a -> (String -> a) -> Entries -> a
foldrEntries next done fail' es = runIdentity $ return . fst =<< runWriterT
foldIt
  where
    foldIt = foldrEntriesW (\e -> return . next e) (return done) ((return
:: Monad m => a -> WriterT () m a) . fail') es

A second option is to give foldIt a type signature.  Unfortunately if you
want the a in foldIt to match the a in foldEntries, you have to use scoped
type variables extension.  Normally the two signatures are not related and
the compiler figures both a's are not the same as each other.

{-# LANGUAGE ScopedTypeVariables #-}

...

foldrEntries :: forall a. (Entry -> a -> a) -> a -> (String -> a) ->
Entries -> a
foldrEntries next done fail' es = runIdentity $ return . fst =<< runWriterT
foldIt
  where
    foldIt :: Monad m => WriterT () m a
    foldIt = foldrEntriesW (\e -> return . next e) (return done) (return .
fail') es


On Fri, Nov 20, 2015 at 7:14 AM, Martin Vlk <[email protected]> wrote:

> Hi I have two functions, foldrEntries and foldrEntriesW, where the
> latter is a WriterT version of the former. Here are the type signatures:
>
> foldrEntries :: (Entry -> a -> a) ->
>                 a ->
>                 (String -> a) ->
>                 Entries ->
>                 a
>
> foldrEntriesW :: (Monoid w, Monad m) =>
>                  (Entry -> a -> WriterT w m a) ->
>                  WriterT w m a ->
>                  (String -> WriterT w m a) ->
>                  Entries ->
>                  WriterT w m a
>
> I want to implement foldrEntries in terms of foldrEntriesW using the
> Identity monad and ignore/not use the writer result. I am doing this in
> order to reuse the foldrEntriesW implementation and avoid code duplication.
>
> This is what I have so far:
> http://lpaste.net/145641
>
> But the compiler complains about ambiguous type for the writer reult I
> am ignoring (message in the above lpaste).
>
> Normally I think the way around this is to provide explicit type
> annotation for "foldIt", but in this case the result type depends on the
> type of "a" in foldrEntries type and I don't know how to express this
> and make the compiler happy.
>
> (I was able to make it work by calling "tell ()", basically writing a
> dummy value, which lets compiler know what the type is, but this is not
> so good - I don't want to make artificial function calls like this.)
>
> Can anybody help me with that?
>
> Many Thanks
> Martin
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151120/dacb4324/attachment-0001.html>

------------------------------

Message: 3
Date: Sat, 21 Nov 2015 00:21:52 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Ambiguous type of WriterT result I am
        not     using
Message-ID:
        <capy+zdsxlusgbghkydjslrr+y8ibd_e-pwdtrhw5+ys26aq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Martin,

But the compiler complains about ambiguous type for the writer reult I
> am ignoring (message in the above lpaste).
>

There are a number of types going on here, and the one that's ambiguous is
the monoid w in WriterT w m a.


> Normally I think the way around this is to provide explicit type
> annotation for "foldIt", but in this case the result type depends on the
> type of "a" in foldrEntries type and I don't know how to express this
> and make the compiler happy.
>

David's ScopedTypeVariables solution is perfectly cromulent. Here's another
one without any pragmas:

foldrEntries ::
      (Entry -> a -> a)
   -> a
   -> (String -> a)
   -> Entries
   -> a
foldrEntries next done fail' =
   isoR . foldrEntriesW (isoL .: next) (isoL done) (isoL . fail')
   where
   isoL :: a -> WriterT () Identity a
   isoL = return
   isoR :: WriterT () Identity a -> a
   isoR = fst . runIdentity . runWriterT

The (.:) is from Data.Composition.

The isoL and isoR witness the isomorphism, and foldrEntries is written in a
point-minimized form that makes it transparent that it's a specialization
of foldrEntriesW.

Do eschew verbosities like "return . fst =<< runWriterT". (Hlint should be
programmed to catch this. It doesn't yet.) A return that's too near a
monadic bind sets off alarms among professional haskell engineers.


> (I was able to make it work by calling "tell ()", basically writing a
> dummy value, which lets compiler know what the type is, but this is not
> so good - I don't want to make artificial function calls like this.)
>

Good call.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151121/3f604bf1/attachment-0001.html>

------------------------------

Message: 4
Date: Fri, 20 Nov 2015 21:38:44 -0500
From: Jeon-Young Kang <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] RDF with Haskell
Message-ID:
        <calwtik_n8yapkyqwqfbpfahnfucjzfctmq9sbzpnuvl5z5a...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello.

I am a newbie learning Haskell.

I'd like to import RDF in Haskell as well as to do SPARQL.

I went through RDF4H, Swish, and so on.

But it is still difficult to understand them for me.

Anyone can suggest me to learn that? or recommend any kinds of books or
tutorials?

Sincerely,
Jeon-Young

--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151120/aa007e86/attachment-0001.html>

------------------------------

Subject: Digest Footer

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


------------------------------

End of Beginners Digest, Vol 89, Issue 35
*****************************************

Reply via email to