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. Defining ExtensionClass (Maybe a) instance in xmonad.
(Dmitriy Matrosov)
2. Let the compiler do the work (Elias Diem)
3. Re: Let the compiler do the work (David McBride)
4. Re: Defining ExtensionClass (Maybe a) instance in xmonad.
(Brandon Allbery)
5. Re: Let the compiler do the work (Elias Diem)
----------------------------------------------------------------------
Message: 1
Date: Mon, 19 Jan 2015 17:01:44 +0400
From: Dmitriy Matrosov <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Defining ExtensionClass (Maybe a)
instance in xmonad.
Message-ID:
<CAFdVUFnHykRvjMiEBfXnovCGbQuU+LU_N9wqEWBGkDzjgCg=x...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi.
I've tried to define (Maybe a) instance for ExtensionClass from
XMonad/Core.hs
in such way, that extensionType value would use the same data constructor as
was used for the type a itself. But the code below typechecks only, if i add
(Show a) and (Read a) constraints to (Maybe a) instance definition, what
makes
such definition useless for types, which do not have these instances and do
not want to use PersistentExtension .
How can i define (Maybe a) instance without (Show a) and (Read a)
constraints?
> {-# LANGUAGE ExistentialQuantification #-}
> import Data.Typeable
> -- This one does not typecheck
> --instance ExtensionClass a => ExtensionClass (Maybe a) where
> instance (Show a, Read a, ExtensionClass a) => ExtensionClass (Maybe a)
where
> initialValue = Nothing
> extensionType x = let Just i = (Just initialValue) `asTypeOf` x
> in case extensionType i of
> PersistentExtension _ -> PersistentExtension x
> StateExtension _ -> StateExtension x
Here is class definition from XMonad/Core.hs:
> class Typeable a => ExtensionClass a where
> initialValue :: a
> extensionType :: a -> StateExtension
> extensionType = StateExtension
> data StateExtension =
> forall a. ExtensionClass a => StateExtension a
> | forall a. (Read a, Show a, ExtensionClass a) => PersistentExtension a
--
Dmitriy Matrosov
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20150119/4a10ef9e/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 19 Jan 2015 15:29:11 +0100
From: Elias Diem <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Let the compiler do the work
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi there
I'm referring to a post from Stefan H?ck and will quote from
there:
http://article.gmane.org/gmane.comp.lang.haskell.beginners/14198
<quote>
Now, load this into GHCi or compile with GHC. If it compiles, you're
on the right track. Now, you want to implement it using a fold
(try both, foldl and foldr):
last5 :: [a] -> Maybe a
last5 xs = foldr _ _ xs
The underscores are 'type holes'. This tells the compiler to give you
some information about what is supposed to be placed at the two
positions. For the moment, we are only interested in the types of the
things that go there. The compiler will tell you, that
the hole at the first position is of type
a -> Maybe a -> Maybe a
</quote>
How does the compiler tell me this? I didn't find any flags
for GHC to turn this on. What do I miss?
--
Greetings
Elias
------------------------------
Message: 3
Date: Mon, 19 Jan 2015 09:41:07 -0500
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] Let the compiler do the work
Message-ID:
<can+tr41fdc+3eqh0m_puknavelmwoba_lj+cne-u3hiu+4p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I believe the feature "typed holes" first came about around ghc 7.8. I'm
not sure if there ever was a pragma for it because it got everyone so
excited it was just made to default on from its inception.
On Mon, Jan 19, 2015 at 9:29 AM, Elias Diem <[email protected]> wrote:
> Hi there
>
> I'm referring to a post from Stefan H?ck and will quote from
> there:
>
> http://article.gmane.org/gmane.comp.lang.haskell.beginners/14198
>
> <quote>
> Now, load this into GHCi or compile with GHC. If it compiles, you're
> on the right track. Now, you want to implement it using a fold
> (try both, foldl and foldr):
>
> last5 :: [a] -> Maybe a
> last5 xs = foldr _ _ xs
>
> The underscores are 'type holes'. This tells the compiler to give you
> some information about what is supposed to be placed at the two
> positions. For the moment, we are only interested in the types of the
> things that go there. The compiler will tell you, that
> the hole at the first position is of type
>
> a -> Maybe a -> Maybe a
> </quote>
>
> How does the compiler tell me this? I didn't find any flags
> for GHC to turn this on. What do I miss?
>
> --
> Greetings
> Elias
>
>
> _______________________________________________
> 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/20150119/ee5dc27b/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 19 Jan 2015 09:55:40 -0500
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] Defining ExtensionClass (Maybe a)
instance in xmonad.
Message-ID:
<cakfcl4vwxmhjautrrxn8vuspglgpyj9xwvblafecdcu1mcu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Jan 19, 2015 at 8:01 AM, Dmitriy Matrosov <[email protected]> wrote:
> I've tried to define (Maybe a) instance for ExtensionClass from
> XMonad/Core.hs
> in such way, that extensionType value would use the same data constructor
> as
> was used for the type a itself. But the code below typechecks only, if i
> add
> (Show a) and (Read a) constraints to (Maybe a) instance definition, what
> makes
> such definition useless for types, which do not have these instances and do
> not want to use PersistentExtension .
>
ExtensionClass data is stored in the layout and therefore requires those
constraints. No, there is no magic to cause non-persistent ExtensionClass
data to be stored in some other place different from where the rest of it
is stored.
I'm also wondering how much trouble you can get into by conflicting with
some other ExtensionClass that already uses Maybe.
--
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/20150119/70cacd1b/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 19 Jan 2015 16:56:19 +0100
From: Elias Diem <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Let the compiler do the work
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi David
On 2015-01-19, David McBride wrote:
> I believe the feature "typed holes" first came about around ghc 7.8.
Well that might explain why I can't find anything in GHC 7.4 ;-)
Thanks.
--
Greetings
Elias
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 79, Issue 22
*****************************************