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 (Kim-Ee Yeoh)
   2. Re:  Bool newtype (Theodore Lief Gannon)
   3. Re:  Bool newtype (Imants Cekusins)
   4. Re:  Bool newtype (Imants Cekusins)
   5. Re:  Bool newtype (Imants Cekusins)
   6.  Learning Haskell: More About Algebraic Data      Types
      (Manuel M T Chakravarty)


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

Message: 1
Date: Sun, 7 Aug 2016 22:18:05 +0700
From: Kim-Ee Yeoh <k...@atamo.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:
        <capy+zdrq4myrwnwfu0mqm_ptwdzbwqazoumbueuuk7wphte...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Have you heard of Djinn?

https://hackage.haskell.org/package/djinn

If you punch in the signature of the combine function you're looking for
(rewritten more usefully in Kleisli composition form):

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

you'll get your wish granted. Djinn will magically write combine for you.

It'll work even if you abstract over the concrete types of Int, Integer,
String.

You can popover to the haskell IRC to try it out on the djinn bot there if
installation is too much of a bother.

Best, Kim-Ee

On Saturday, August 6, 2016, 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 <javascript:;>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>


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

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

Message: 2
Date: Sun, 7 Aug 2016 13:48:24 -0700
From: Theodore Lief Gannon <tan...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Bool newtype
Message-ID:
        <CAJoPsuAQ6SHvvsQg+v++H7xPYPkUtsp7MCAadca939pW4=c...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

As-is, no. As Michael said, that would defeat the purpose of a newtype.
However, there is a generic way: all newtypes are given instances of
Coercible, so instead of individual unwrap functions you can use coerce
from Data.Coerce.

On Aug 7, 2016 7:59 AM, "Imants Cekusins" <ima...@gmail.com> wrote:

> > newtype B = B { toBool :: Bool }
>
> yep, this works well. toBool b1 is easy enough ;)
>
> I wondered if there was an easy (with deriving etc) way to test B as it
> is. If there isn't - no biggie.
>
>
> ​
>
> _______________________________________________
> 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/20160807/c4713506/attachment-0001.html>

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

Message: 3
Date: Sun, 7 Aug 2016 23:12:26 +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: Re: [Haskell-beginners] Bool newtype
Message-ID:
        <CAP1qina-wpH9O42rwCW=Yc-_DT8YbPNA0BOBEJguMyap=66...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thank you Theodore.

> Data.Coerce

Could you hint the name of the package, please? Does it coerce safely?

If Coercible does not type check, another option could be to define a class
and a function that works similar to if statement, constrained to instances
of this class.

class Newtype_base nt base where
  base_t::nt -> base

if_::Newtype_base nt Bool =>
   nt -> then -> else

Standard if is clearer of course but with a few newtypes being passed
around, this may save some key strokes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160807/51f16e88/attachment-0001.html>

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

Message: 4
Date: Sun, 7 Aug 2016 23:15:43 +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: Re: [Haskell-beginners] Bool newtype
Message-ID:
        <CAP1qinaytK21RJ=ZBTq8F5GJd7=9VO=vs+fm_nyapznl3pr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

... this may be correct:

if_::Newtype_base nt Bool =>
   nt -> result -> result -> result
if_ if0 then0 else0 = ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160807/f41c5892/attachment-0001.html>

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

Message: 5
Date: Sun, 7 Aug 2016 23:47:15 +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: Re: [Haskell-beginners] Bool newtype
Message-ID:
        <CAP1qinaLV0zPB=mHPntDfsQHoG4yJGHWU=ir1qz9bothsp9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

found it:

https://wiki.haskell.org/GHC/Coercible

yep, it type checks.

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

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

Message: 6
Date: Mon, 8 Aug 2016 14:11:09 +1000
From: Manuel M T Chakravarty <c...@justtesting.org>
To: beginners@haskell.org
Subject: [Haskell-beginners] Learning Haskell: More About Algebraic
        Data    Types
Message-ID: <94290869-e4bb-4c82-a511-3c718a0ac...@justtesting.org>
Content-Type: text/plain; charset=utf-8

We just published a new chapter in our online Haskell tutorial ”Learning 
Haskell”:

  http://learn.hfm.io

This seventh chapter expands on algebraic data types by discussing parametric & 
recursive data types. It also includes a small graphics library to graphically 
render binary tries as you construct and manipulate them.

Happy Learning!
Manuel



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

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 8
****************************************

Reply via email to