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:  Help on first program (John M. Dlugosz)
   2. Re:  Help on first program (Brandon Allbery)
   3.  Why is this not a "category"? (John M. Dlugosz)
   4. Re:  Why is this not a "category"? (Arjun Comar)
   5.  understanding MTL (Dennis Raddle)


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

Message: 1
Date: Fri, 28 Mar 2014 23:13:19 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Help on first program
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 3/28/2014 6:56 PM, Brandon Allbery wrote:
> It uses all of them to get the type, yes. And the more specific pattern must 
> come first;
> the first one always matches in this case because `n` doesn't give it any way 
> not to
> match. If you had warnings enabled, the compiler should have warned you that 
> the second
> form wouldn't be matched (although you may also need optimization turned on).

I was wondering about that.  I'll look for warning flags.  I was loading into 
GHCi rather 
than running the compiler from the command line.

>
> The compiler doesn't see the different implementations as independent, and in 
> fact doesn't
> see multiple implementations of the function at all at type resolution time; 
> it's
> translated to a single function applying `case` to the parameters to 
> determine which
> clause of the body to evaluate.

Can they be spread out among different source files or be discontiguous within 
one file?





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

Message: 2
Date: Sat, 29 Mar 2014 00:22:31 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Help on first program
Message-ID:
        <CAKFCL4W0bQhC_ikTi5Y7OuoZ0+vVgJ=4avnFxMbssg=vhc+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sat, Mar 29, 2014 at 12:13 AM, John M. Dlugosz
<[email protected]>wrote:

> On 3/28/2014 6:56 PM, Brandon Allbery wrote:
>
>> The compiler doesn't see the different implementations as independent,
>> and in fact doesn't
>>
> see multiple implementations of the function at all at type resolution
>> time; it's
>> translated to a single function applying `case` to the parameters to
>> determine which
>> clause of the body to evaluate.
>>
>
> Can they be spread out among different source files or be discontiguous
> within one file?


Neither one; they must be together in the same file with nothing
intervening, since they get rewritten into a single function. They also
must all have the same number of parameters, even if one of them could take
advantage of eta reduction (see
http://www.haskell.org/haskellwiki/Eta_conversion), since the combination
into a single function uses a common set of parameters.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140329/acc95013/attachment-0001.html>

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

Message: 3
Date: Sat, 29 Mar 2014 00:18:46 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Why is this not a "category"?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

on 
https://en.wikibooks.org/w/index.php?title=Haskell/Category_theory&stable=0#Hask.2C_the_Haskell_category

the second exercise in the box (see illustration there) asks
"(Harder.) If we add another morphism to the above example, it fails to be a 
category. 
Why? Hint: think about associativity of the composition operation."

There are no answers-to-exercises.  Can someone explain to me why adding 
another function 
with the same type causes the Haskell type system to no longer form the Hask 
category?

(scratching head)



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

Message: 4
Date: Sat, 29 Mar 2014 01:47:01 -0400
From: Arjun Comar <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Why is this not a "category"?
Message-ID:
        <CADjRcrUUugZPzvUeyUZUT=wq5pjv3kzu0344esbubq54hk-...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

You're misreading the question. It's asking you to show that the category
induced by the <= relation fails associativity if you add an extra
morphism.
On Mar 29, 2014 1:19 AM, "John M. Dlugosz" <[email protected]> wrote:

> on https://en.wikibooks.org/w/index.php?title=Haskell/
> Category_theory&stable=0#Hask.2C_the_Haskell_category
>
> the second exercise in the box (see illustration there) asks
> "(Harder.) If we add another morphism to the above example, it fails to be
> a category. Why? Hint: think about associativity of the composition
> operation."
>
> There are no answers-to-exercises.  Can someone explain to me why adding
> another function with the same type causes the Haskell type system to no
> longer form the Hask category?
>
> (scratching head)
>
> _______________________________________________
> 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/20140329/882071a1/attachment-0001.html>

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

Message: 5
Date: Sat, 29 Mar 2014 03:32:09 -0700
From: Dennis Raddle <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] understanding MTL
Message-ID:
        <cakxlvopnp0alc48r8g5fapjngmxm15x0v9+gjmi9l+0unq7...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I had an interaction on #haskell today which left me utterly confused but
desiring to understand what happened. I was talking about a program in
which I was using stacks of monad transformers, inspiration taken from the
paper "Monad Transformers: Step by Step". So for example I wanted to
combine state and error handling in a Monadic type called "Er".

data ErState = ErState StdGen

newtype Er a = Er { runEr :: ErrorT String (State ErState) a }
    deriving(Monad, MonadError String, MonadState ErState)

Note that ErState holds a random generator. I had the idea to make a
typeclass of monadic types that hold random generators because I'll be
using them in other types all over my application. Something like

class Monad m => RandomMonad m where
  getGen :: m StdGen
  putGen :: StdGen -> m ()

Then I can write functions like this:

myRandoms :: (Random a, RandomMonad m) => m [a]
myRandoms = do
  g <- getGen
  let (g1, g2) = split g
      values = randoms g1
  putGen g2
  return values

So then mm_freak on #haskell noticed that I had written a function with a
signature like

process :: Int -> Er Int

He said, no no no functions should be agnostic with regard to data
structure. It should look something like
process :: (RandomMonad m, MonadError m, MonadState m) => Int -> m Int

He then said I don't want to put StateT and ErrorT in the same newtype
declaration, so it would be something like
newtype Er m a = Er { runEr :: StateT ErState m a }

On this point I'm confused. I don't know how to get from a line like the
above to eventually making a type that combines error handling and state.
Furthermore I need to define instances for things like MonadError. He got
me started with the line

instance MonadError e m => MonadError e (Er m) where
... define throwError and catchError which I have no idea how to do ...

So where we left it, I was confused and didn't understand anything.

Rather than just getting the answers, I want to try to understand this, but
I feel like I must need more background. This must be the kind of code that
is in the monad transformer library. Is there a guide to understanding that
somewhere?

D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140329/14fcbd9c/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 69, Issue 46
*****************************************

Reply via email to