Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  My Continuation doesn't typecheck (David McBride)
   2. Re:  My Continuation doesn't typecheck (martin)
   3.  Bool newtype (Imants Cekusins)


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

Message: 1
Date: Sat, 6 Aug 2016 13:01:00 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] My Continuation doesn't typecheck
Message-ID:
        <CAN+Tr43tech2-29oECPAWjMEkdX2cA+m=mVHdGH+v6_-=z4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

The only way to do this is to do it step by step.
:t combine
combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t

>:t combine 9
combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t

>:t f1
f1 :: Int -> (Integer -> r) -> r
>:t combine 9 f1
combine 9 f1 :: (Integer -> t) -> t

>:t f2
f2 :: Integer -> (String -> r) -> r
>:t combine 9 f1 f2
combine 9 f1 f2 :: (String -> r) -> r

At some point the t2 in combine becomes a function, which causes the rest
of the type to change.  I feel like combine was meant to be something else,
f (g a) or g (f a) or something else, but I'm not sure what.


On Sat, Aug 6, 2016 at 4:03 AM, martin <martin.drautzb...@web.de> wrote:

> Hello all,
>
> in order to gain some intuition about continuations, I tried the following:
>
> -- two functions accepting a continuation
>
>         f1 :: Int -> (Integer->r) -> r
>         f1 a c = c $ fromIntegral (a+1)
>
>         f2 :: Integer -> (String -> r) -> r
>         f2 b c = c $ show b
>
>         -- combine the two functions into a single one
>
>         run1 :: Int -> (String -> r) -> r
>         run1 a = f1 a f2
>
>
>         -- *Main> run1 9 id
>         -- "10"
>
> So far so good.
>
>
> Then I tried to write a general combinator, which does not have f1 and f2
> hardcoded:
>
>         combine a f g = f a g
>
>         -- This also works
>
>         -- *Main> combine 9 f1 f2 id
>         -- "10"
>
>
> What confuses me is the the type of combine. I thought it should be
>
>         combine :: Int ->
>         (Int -> (Integer->r) -> r) ->        -- f1
>         (Integer -> (String -> r) -> r) ->   -- f2
>         ((String -> r) -> r)
>
>
> but that doesn't typecheck:
>
>         Couldn't match expected type ‘(String -> r) -> r’
>         with actual type ‘r’
>
>
> Can you tell me where I am making a mistake?
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160806/3146100d/attachment-0001.html>

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

Message: 2
Date: Sun, 7 Aug 2016 13:05:02 +0200
From: martin <martin.drautzb...@web.de>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] My Continuation doesn't typecheck
Message-ID: <57a715de.7060...@web.de>
Content-Type: text/plain; charset=utf-8

David,

I used your method of hardcoding some of the parameters to find the correct 
type of 'combine'. It is not at all what I
expected or wanted, but here it is:

combine :: Int -> (Int -> (Integer -> (String -> r) -> r) -> (String -> r) -> r 
-> String) ->
                          (Integer -> (String -> r) -> r) -> (String -> r) -> r 
-> String



Not sure what this is trying to tell me.


Am 08/06/2016 um 07:01 PM schrieb David McBride:
> The only way to do this is to do it step by step.
> :t combine
> combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t
> 
>>:t combine 9
> combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t
> 
>>:t f1
> f1 :: Int -> (Integer -> r) -> r
>>:t combine 9 f1
> combine 9 f1 :: (Integer -> t) -> t
> 
>>:t f2
> f2 :: Integer -> (String -> r) -> r
>>:t combine 9 f1 f2
> combine 9 f1 f2 :: (String -> r) -> r
> 
> At some point the t2 in combine becomes a function, which causes the rest of 
> the type to change.  I feel like combine
> was meant to be something else, f (g a) or g (f a) or something else, but I'm 
> not sure what.
> 
> 
> On Sat, Aug 6, 2016 at 4:03 AM, martin <martin.drautzb...@web.de 
> <mailto:martin.drautzb...@web.de>> wrote:
> 
>     Hello all,
> 
>     in order to gain some intuition about continuations, I tried the 
> following:
> 
>     -- two functions accepting a continuation
> 
>             f1 :: Int -> (Integer->r) -> r
>             f1 a c = c $ fromIntegral (a+1)
> 
>             f2 :: Integer -> (String -> r) -> r
>             f2 b c = c $ show b
> 
>             -- combine the two functions into a single one
> 
>             run1 :: Int -> (String -> r) -> r
>             run1 a = f1 a f2
> 
> 
>             -- *Main> run1 9 id
>             -- "10"
> 
>     So far so good.
> 
> 
>     Then I tried to write a general combinator, which does not have f1 and f2 
> hardcoded:
> 
>             combine a f g = f a g
> 
>             -- This also works
> 
>             -- *Main> combine 9 f1 f2 id
>             -- "10"
> 
> 
>     What confuses me is the the type of combine. I thought it should be
> 
>             combine :: Int ->
>             (Int -> (Integer->r) -> r) ->        -- f1
>             (Integer -> (String -> r) -> r) ->   -- f2
>             ((String -> r) -> r)
> 
> 
>     but that doesn't typecheck:
> 
>             Couldn't match expected type ‘(String -> r) -> r’
>             with actual type ‘r’
> 
> 
>     Can you tell me where I am making a mistake?
> 
>     _______________________________________________
>     Beginners mailing list
>     Beginners@haskell.org <mailto:Beginners@haskell.org>
>     http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners 
> <http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners>
> 
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 



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

Message: 3
Date: Sun, 7 Aug 2016 13:45:54 +0200
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Bool newtype
Message-ID:
        <CAP1qinZfZDp-nU_iN-5BZo1zw6a=ekeboegc8_-aevl3cgt...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

for a Bool-like newtype:

newtype B = B Bool

, is there an easy way to use this newtype B in place of Bool?

e.g.

let b1 = B True
in if b1 then 1 else 0

?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160807/73382b87/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 98, Issue 6
****************************************

Reply via email to