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:  Monad instances and type synonyms (Brent Yorgey)
   2.  help with lists and tuples (Miro Karpis)
   3. Re:  help with lists and tuples (Alexander O'Neill)
   4. Re:  help with lists and tuples (Bob Ippolito)
   5. Re:  help with lists and tuples (Miro Karpis)


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

Message: 1
Date: Sun, 14 Apr 2013 08:09:16 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Monad instances and type synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sat, Apr 13, 2013 at 05:03:57PM -0800, Christopher Howard wrote:
> I am playing around with some trivial code (for learning purposes) I
> wanted to take
> 
> code:
> --------
> -- SaleVariables a concrete type defined early
> 
> -- `Adjustment' represents adjustment in a price calculation
> -- Allows functions of type (a -> Adjustment a) to be composed
> -- with an appropriate composition function
> type Adjustment a = SaleVariables -> a
> --------
> 
> And put it into
> 
> code:
> --------
> instance Monad Adjustment where
> 
>   (>>=) = ...
>   return = ...
> --------
> 
> If I try this, I get
> 
> code:
> --------
> Type synonym `Adjustment' should have 1 argument, but has been given none
> In the instance declaration for `Monad Adjustment'
> --------
> 
> But if I give an argument, then it doesn't compile either (it becomes a
> "*" kind). And I didn't want to make the type with a regular "data"
> declaration either, because then I have to give it a constructor, which
> doesn't fit with what I want the type to do.

Sorry, what you're trying to do is simply not possible.  Type synonyms
must always be fully applied.  So if you want to make Adjustment an
instance of Monad then you have to make it a newtype.

However... Adjustment already *is* an instance of Monad!  (In
particular ((->) e) is an instance for any type e.)  So there's no
need for you to redeclare an instance yourself.  These days I think
you just have to import Control.Monad to bring the instance in scope.

-Brent



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

Message: 2
Date: Mon, 15 Apr 2013 01:04:02 +0200
From: Miro Karpis <[email protected]>
Subject: [Haskell-beginners] help with lists and tuples
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cajnnbxfkuxnm9mgnvss6xfu2p81dzn4azy4-wdsnhg2trfi...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Please can you help me with this? What I want is to have on input a list of
tuple (size 2) and on output list of floats. So now I'm returning only
float instead of a list. But unfortunately I can't figure out how to
implement the list......


sigmoid :: Float -> Float
sigmoid x = 1.0 / (1 + exp (-x))

nActivation :: (Float,Float) -> Float
nActivation (x,y) = sigmoid(x*y)

nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum [] = []
nActivationSum (inputs:weights) = *nActivation* (inputs, weights)



Couldn't match expected type `[Float]' with actual type `Float'
    In the return type of a call of `nActivation'
    In the expression: nActivation (inputs, weights)
    In an equation for `nActivationSum':
        nActivationSum (inputs : weights) = nActivation (inputs, weights)


thanks,
m.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130415/f1b34947/attachment-0001.htm>

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

Message: 3
Date: Sun, 14 Apr 2013 16:18:03 -0700
From: Alexander O'Neill <[email protected]>
Subject: Re: [Haskell-beginners] help with lists and tuples
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

It seems like you want to set up a recursive function. So you want to take one 
tuple out of the list of tuples, perform your sum function on it, and then call 
the recursive function on the remainder of the list.  Something like this, 
maybe?

nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum [] = []
nActivationSum ((input,weight) : rest) = nActivation (input, weight) : nActivat\
ionSum rest


On 2013-04-14, at 4:04 PM, Miro Karpis <[email protected]> wrote:

> Please can you help me with this? What I want is to have on input a list of 
> tuple (size 2) and on output list of floats. So now I'm returning only float 
> instead of a list. But unfortunately I can't figure out how to implement the 
> list......
> 
> 
> sigmoid :: Float -> Float
> sigmoid x = 1.0 / (1 + exp (-x))
> 
> nActivation :: (Float,Float) -> Float
> nActivation (x,y) = sigmoid(x*y) 
> 
> nActivationSum :: [(Float, Float)] -> [Float]
> nActivationSum [] = []
> nActivationSum (inputs:weights) = nActivation (inputs, weights)
> 
> 
> 
> Couldn't match expected type `[Float]' with actual type `Float'
>     In the return type of a call of `nActivation'
>     In the expression: nActivation (inputs, weights)
>     In an equation for `nActivationSum':
>         nActivationSum (inputs : weights) = nActivation (inputs, weights)
> 
> 
> thanks,
> m.
> _______________________________________________
> 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/20130414/f7b0e29c/attachment-0001.htm>

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

Message: 4
Date: Sun, 14 Apr 2013 16:18:37 -0700
From: Bob Ippolito <[email protected]>
Subject: Re: [Haskell-beginners] help with lists and tuples
To: [email protected],  The Haskell-Beginners Mailing List -
        Discussion of primarily beginner-level topics related to Haskell
        <[email protected]>
Message-ID:
        <cacwmpm-wqzu502vfbvpxc98ga2zo9zzyquzmsmftznwbzl2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It looks like you want this instead:

nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum (xy : xys) = nActivation xy : nActivationSum xys
nActivationSum [] = []

This pattern is more commonly expressed with map like this:

nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum inputsAndWeights = map nActivation inputsAndWeights

Or you could write it a bit shorter in point-free style:

nActivationSum :: [(Float, Float)] -> [Float]
nActivationSum = map nActivation



On Sun, Apr 14, 2013 at 4:04 PM, Miro Karpis <[email protected]>wrote:

> Please can you help me with this? What I want is to have on input a list
> of tuple (size 2) and on output list of floats. So now I'm returning only
> float instead of a list. But unfortunately I can't figure out how to
> implement the list......
>
>
> sigmoid :: Float -> Float
> sigmoid x = 1.0 / (1 + exp (-x))
>
> nActivation :: (Float,Float) -> Float
> nActivation (x,y) = sigmoid(x*y)
>
> nActivationSum :: [(Float, Float)] -> [Float]
> nActivationSum [] = []
> nActivationSum (inputs:weights) = *nActivation* (inputs, weights)
>
>
>
> Couldn't match expected type `[Float]' with actual type `Float'
>     In the return type of a call of `nActivation'
>     In the expression: nActivation (inputs, weights)
>     In an equation for `nActivationSum':
>         nActivationSum (inputs : weights) = nActivation (inputs, weights)
>
>
> thanks,
> m.
>
> _______________________________________________
> 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/20130414/73a320e8/attachment-0001.htm>

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

Message: 5
Date: Mon, 15 Apr 2013 08:11:05 +0200
From: Miro Karpis <[email protected]>
Subject: Re: [Haskell-beginners] help with lists and tuples
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <cajnnbxfk_jwhu1bvrxuwas0ure0qy21domjprxuprssecss...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

millions of thanks for all the info.

m.


On Mon, Apr 15, 2013 at 1:21 AM, Paul Higham <[email protected]> wrote:

> Wouldn't it do just to have
>
> nActivationSum = map nActivation
>
> or am I missing your intent here?
>
> Note that on the left-hand side of the last equation inputs would have to
> have type (Float, Float) and weights would have to have type
> [(Float,Float)], but on the right-hand side both inputs and weights have to
> be Float.  The result of
> nActivation (inputs, weights) is Float, but the result of
> nActivationSum (inputs:weights) should be [(Float,Float)], hence the error
> message.
>
> :: paul
>
> On 2013-04-14, at 16:04 , Miro Karpis wrote:
>
> Please can you help me with this? What I want is to have on input a list
> of tuple (size 2) and on output list of floats. So now I'm returning only
> float instead of a list. But unfortunately I can't figure out how to
> implement the list......
>
>
> sigmoid :: Float -> Float
> sigmoid x = 1.0 / (1 + exp (-x))
>
> nActivation :: (Float,Float) -> Float
> nActivation (x,y) = sigmoid(x*y)
>
> nActivationSum :: [(Float, Float)] -> [Float]
> nActivationSum [] = []
> nActivationSum (inputs:weights) = *nActivation* (inputs, weights)
>
>
>
> Couldn't match expected type `[Float]' with actual type `Float'
>     In the return type of a call of `nActivation'
>     In the expression: nActivation (inputs, weights)
>     In an equation for `nActivationSum':
>         nActivationSum (inputs : weights) = nActivation (inputs, weights)
>
>
> thanks,
> m.
>  _______________________________________________
> 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/20130415/02d15562/attachment.htm>

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

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


End of Beginners Digest, Vol 58, Issue 28
*****************************************

Reply via email to