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.  Unicode Fanatic ? How to use? (John M. Dlugosz)
   2. Re:  Unicode Fanatic -- How to use? (David McBride)
   3. Re:  Question about define my own typeclass (ke dou)


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

Message: 1
Date: Thu, 27 Mar 2014 15:51:22 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Unicode Fanatic ? How to use?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I love using non-ASCII characters!  Even my name, D?ugosz, needs Latin-2.  My 
wife's name, 
?, doesn't even use Latin characters.  I've inserted thousands of em and en 
dashes in 
Wikipedia and can easily type at least three kinds of blank space.

When I was in a college class on programming theory, we studied Backus?s FP 
System and I 
corresponded with John Backus to ask a question the prof couldn't handle, and 
he sent me 
the TeX definitions he used, so my homework really did match the appearance of 
the 
textbook.  But that's another story.  I managed to get my name in the Unicode 3 
hardcopy book.

So, I relish the ability to use proper math symbols in Haskell.

Here is an example of what I've tried:

        {-# LANGUAGE UnicodeSyntax #-}

        import Prelude.Unicode

        f x y = x?y

        result = f ? id

        -- problem = ? True

Is the UnicodeSyntax pragma a different mechanism than the modules?  Do I need 
to state 
both, or do they clash, or work together, or what?

Do I need to list all the individual modules (up to 12 of them) as needed (see 
http://hackage.haskell.org/package/base-unicode-symbols) or can they be brought 
in as one 
easy chunk, as the package itself is one thing?

The compiler does not like the ? symbol, with or without the pragma.
http://hackage.haskell.org/package/base-unicode-symbols-0.2.2.4/docs/Prelude-Unicode.html
clearly shows it (the first one!) and it appears in the module source so 
presumably it 
didn't choke there.  I recall seeing that it is one of the "problematic" 
symbols but GHC 
has some extensions.

OTOH, I read that ? can?t be made to work, which is sad.  Maybe ? (which is a 
symbol) can 
be used instead?



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

Message: 2
Date: Thu, 27 Mar 2014 17:13:38 -0400
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] Unicode Fanatic -- How to use?
Message-ID:
        <can+tr42_jw2fhh+vyecdllsn9vny8ayktkd5ogq2ste0+re...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I think the problem is that ? is unary.  You can use problem = (?) True.
I'm not sure that there isn't a way around this.


On Thu, Mar 27, 2014 at 4:51 PM, John M. Dlugosz
<[email protected]>wrote:

> I love using non-ASCII characters!  Even my name, D?ugosz, needs Latin-2.
>  My wife's name, ?, doesn't even use Latin characters.  I've inserted
> thousands of em and en dashes in Wikipedia and can easily type at least
> three kinds of blank space.
>
> When I was in a college class on programming theory, we studied Backus?s
> FP System and I corresponded with John Backus to ask a question the prof
> couldn't handle, and he sent me the TeX definitions he used, so my homework
> really did match the appearance of the textbook.  But that's another story.
>  I managed to get my name in the Unicode 3 hardcopy book.
>
> So, I relish the ability to use proper math symbols in Haskell.
>
> Here is an example of what I've tried:
>
>         {-# LANGUAGE UnicodeSyntax #-}
>
>         import Prelude.Unicode
>
>         f x y = x?y
>
>         result = f ? id
>
>         -- problem = ? True
>
> Is the UnicodeSyntax pragma a different mechanism than the modules?  Do I
> need to state both, or do they clash, or work together, or what?
>
> Do I need to list all the individual modules (up to 12 of them) as needed
> (see http://hackage.haskell.org/package/base-unicode-symbols) or can they
> be brought in as one easy chunk, as the package itself is one thing?
>
> The compiler does not like the ? symbol, with or without the pragma.
> http://hackage.haskell.org/package/base-unicode-symbols-
> 0.2.2.4/docs/Prelude-Unicode.html
> clearly shows it (the first one!) and it appears in the module source so
> presumably it didn't choke there.  I recall seeing that it is one of the
> "problematic" symbols but GHC has some extensions.
>
> OTOH, I read that ? can?t be made to work, which is sad.  Maybe ? (which
> is a symbol) can be used instead?
>
> _______________________________________________
> 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/20140327/1c389b1a/attachment-0001.html>

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

Message: 3
Date: Thu, 27 Mar 2014 17:15:52 -0400
From: ke dou <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question about define my own
        typeclass
Message-ID:
        <cag1_ucq57bzukpwb57prun4l8huo6phy29653aso2yipkbf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks a lot! That really helps me understand the typeclass and solve my
problem.

Best,
Ke


On Thu, Mar 27, 2014 at 12:36 PM, Mateusz Kowalczyk <[email protected]
> wrote:

> On 27/03/14 15:49, ke dou wrote:
> > Thanks for your reply.
> >
> > Yes, I understand that if I specify the 'b' to 'Prelude.Bool', it should
> > work, but what if I also want use the typeclass Conversion to convert
> other
> > types other than MyBool, like MyInt, or MyString?
> >
> > --Ke
> >
> > On Thu, Mar 27, 2014 at 11:36 AM, Brandon Allbery <[email protected]
> >wrote:
> >
> >> On Thu, Mar 27, 2014 at 11:28 AM, ke dou <[email protected]> wrote:
> >>
> >>>     class Conversion a where
> >>>         conversion :: a  -> b
> >>>
> >>
> >> b is completely unspecified here, since it's not defined as part of the
> >> typeclass. The literal meaning of this is that "the caller can request
> any
> >> type it pleases, and you have no way of knowing what it is". So the only
> >> possible result of `conversion` is bottom (e.g. `undefined`).
> >>
> >> This is key: it does NOT mean that `conversion` gets to specify the
> result
> >> type! You can't do that, except by specifying the type in the type
> >> signature.
> >>
> >> --
> >> brandon s allbery kf8nh                               sine nomine
> >> associates
> >> [email protected]
> >> [email protected]
> >> unix, openafs, kerberos, infrastructure, xmonad
> >> http://sinenomine.net
> >>
> >> _______________________________________________
> >> Beginners mailing list
> >> [email protected]
> >> http://www.haskell.org/mailman/listinfo/beginners
> >>
> >>
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
>
> This post is Literate Haskell.
>
> You can specify which type you can coerce to by having the typeclass
> also specify ?b?.
>
> To have more than one type parameter, you'll need the MultiParamTypeClasses
> language extension. Ignore FunctionalDependencies for now.
>
> > {-# LANGUAGE FunctionalDependencies #-}
> > {-# LANGUAGE MultiParamTypeClasses #-}
> > {-# LANGUAGE UnicodeSyntax #-}
> > module C where
>
> First we define our own Bool for demonstration purposes.
>
> > data MyBool = MyTrue | MyFalse
>
> We define the class that also specifies ?b? as follows.
>
> > class SimpleCoercible a b where
> >   coerceSimple ? a ? b
>
> We can now achieve what you want: we can state that ?a? cana be
> coerced into ?b?. Here we state that we can convert to Haskell's Bool.
>
> > instance SimpleCoercible MyBool Bool where
> >   coerceSimple MyTrue = True
> >   coerceSimple MyFalse = False
>
> This works fine:
>
> *C> coerceSimple MyTrue :: Bool
> True
>
> Note that I had to say what output type I wanted here because I'm not
> using it
> in a context that GHC could use to infer it. Just because there's only a
> single
> instance does not matter as anyone could come around and add a new
> instance. In
> fact, let's define one more just to show that you can do it. Let's go
> with the
> old 0 is True and 1 is False.
>
> > instance SimpleCoercible MyBool Integer where
> >   coerceSimple MyTrue = 0
> >   coerceSimple MyFalse = 1
>
> As you can see below, it all works great:
>
> *C> coerceSimple MyTrue :: Integer
> 0
> *C> coerceSimple MyTrue :: Bool
> True
>
>
> Now for something a bit out of scope of the question:
>
> Now what if we wanted to only have a single possible mapping? Say, we
> only want
> MyBool to be coercible to Bool and nothing else? We can use
> FunctionalDependencies language extension. I recommend you look it up if
> you're
> interested, here's an example:
>
>
> > class CoercibleOneWay a b | a ? b where
> >   coerceOneWay ? a ? b
> >
> > instance CoercibleOneWay MyBool Bool where
> >   coerceOneWay MyTrue = True
> >   coerceOneWay MyFalse = False
>
> You might wonder if there's an advantage to doing such a thing. Well,
> yes, GHC
> now always knows what the output type (b) should be just by looking by
> the input
> type (a):
>
> *C> :t coerceOneWay MyTrue
> coerceOneWay MyTrue :: Bool
>
> Note that this is not the case with our previous definition! GHC doesn't
> know
> exactly which ?b? we want:
>
> *C> :t coerceSimple MyTrue
> coerceSimple MyTrue :: SimpleCoercible MyBool b => b
>
>
> Can we do more than this? What if we wanted to be able to coerce the
> types the
> other way too? We could write an instance for
> ?CoercibleOneWay Bool MyBool | b ? a? but that's unwieldy. We can
> instead have
> a single type class which can take us both ways:
>
> > class Coercible a b | a ? b, b ? a where
> >   coerceTo ? a ? b
> >   coerceFrom ? b ? a
> >
> > instance Coercible MyBool Bool where
> >   coerceTo MyTrue = True
> >   coerceTo MyFalse = False
> >
> >   coerceFrom True = MyTrue
> >   coerceFrom False = MyFalse
>
> This now lets us convert between MyBool and Bool freely:
>
> *C> :t coerceTo MyTrue
> coerceTo MyTrue :: Bool
> *C> :t coerceFrom True
> coerceFrom True :: MyBool
>
> With this you can model 1-to-1 mapping between your types and built-in
> types.
>
> Note that another approach would simply be to add an instance for
> ?CoercibleOneWay Bool MyBool?. A nice thing about this approach is that
> you can
> use the overloaded function name:
>
> > instance CoercibleOneWay Bool MyBool where
> >   coerceOneWay True = MyTrue
> >   coerceOneWay False = MyFalse
>
> *C> :t coerceOneWay True
> coerceOneWay True :: MyBool
> *C> :t coerceOneWay MyTrue
> coerceOneWay MyTrue :: Bool
>
> I think it's a matter of preference as to which way you go.
>
>
> --
> Mateusz K.
> _______________________________________________
> 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/20140327/705c002d/attachment.html>

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

Subject: Digest Footer

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


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

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

Reply via email to