From math.simplex at gmail.com Mon Jun 4 03:42:54 2018
From: math.simplex at gmail.com (Graham Gill)
Date: Sun, 3 Jun 2018 23:42:54 -0400
Subject: [Haskell-beginners] incoherent instance question
Message-ID:
Please see the paste: https://pastebin.com/zBim7Zkx
I'm experimenting with defining UpperBounded and LowerBounded typeclasses.
An example type belonging to the latter that is not also Bounded would be
type Natural from Numeric.Natural.
I want to say that if a type is Bounded, then it is also UpperBounded and
LowerBounded. If a type is both UpperBounded and LowerBounded, then it is
also Bounded.
To express the constraints, I need FlexibleInstances and
UndecidableInstances extensions. These allow the module to load into ghci
(8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
overlapping instance error if I try to evaluate minBound, maxBound,
upperBound or lowerBound instantiated to either of the types Foo or Bar.
A solution is to apply the INCOHERENT pragma to the instances at lines 11,
14 and 17. Reading over section 10.8.3.6. Overlapping instances in the GHC
User Guide, I believe I understand. (Is there a better solution?)
In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This gives
me the following behaviour in ghci:
1. minBound, maxBound, upperBound and lowerBound instantiated to type
Foo all function as expected, evaluating to the appropriate lower or upper
bound.
2. upperBound and maxBound instantiated at Bar give overlapping instance
errors for UpperBounded, as expected.
3. lowerBound :: Bar evaluates to C, as expected.
4. minBound :: Bar gives an overlapping instance error for UpperBounded:
*UpperLowerBounded> minBound :: Bar
:141:1: error:
• Overlapping instances for UpperBounded Bar
arising from a use of ‘minBound’
Matching instances:
instance [safe] Bounded a => UpperBounded a
-- Defined at UpperLowerBounded.hs:14:10
instance [safe] UpperBounded Bar -- Defined at
UpperLowerBounded.hs:31:10
• In the expression: minBound :: Bar
In an equation for ‘it’: it = minBound :: Bar
It's #4 that I don't understand. An explanation would be very much
appreciated. (Also, what's a [safe] instance?)
Regards,
Graham
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From rpglover64 at gmail.com Mon Jun 4 05:10:04 2018
From: rpglover64 at gmail.com (Alex Rozenshteyn)
Date: Sun, 3 Jun 2018 22:10:04 -0700
Subject: [Haskell-beginners] incoherent instance question
In-Reply-To:
References:
Message-ID:
>
> I want to say that if a type is Bounded, then it is also UpperBounded and
> LowerBounded.
Seems reasonable
> If a type is both UpperBounded and LowerBounded, then it is also Bounded.
Danger Will Robinson. Nothing stops modules (realistically, in two
different library) from defining incompatible UpperBounded and LowerBounded
instances; for example, I may want `lowerBound :: Bool` to be `True`, while
you may want `upperBound :: Bool` to be `True`; when they are both
imported, bad things can happen. In this case, requiring an Ord constraint
and adding documentation on lawful instances would pretty much solve the
problem, but in general, this is an unwise thing to do.
Specifically, it is usually a bad idea to have a type class that should
have an instance for a type whenever that type has instances of some
combination of other classes.
Three ways around it:
- Use a newtype wrapper: define `newtype LowerUpperBounded` and have the
instance be `(LowerBounded a, UpperBounded a) => Bounded (LowerUpperBounded
a)`
- Defer instance definition to concrete types: if you know that a
specific type has both super-instances, you can explicitly instantiate it
at the sub-instance
- Define a constraint alias: (this requires some more advanced
extensions, so I'm only mentioning it as an option for completeness' sake)
Using `ConstraintKinds`, you can define `type Bounded a = (LowerBounded a,
UpperBounded a)`; this makes the two definitions synonymous.
To your immediate question, I *think* what's happening is that when you're
trying to do `minBound :: Bar` it looks for an instance `Bounded Bar` and
finds the unique one; then it needs to satisfy the constraints, so it looks
for `LowerBounded Bar` and `UpperBounded Bar`, the latter of which has two
possible instances, neither of which is marked overlapping or incoherent.
You'll notice that if you use `-fdefer-type-errors` you will be able to get
the `minBound` of `Bar` (though for some reason you need to bind it to a
variable), but not the `maxBound`.
You should also note that if you use the `OVERLAPPABLE` pragma rather than
the `INCOHERENT` one, you get the same results, and that is generally
considered less risky.
On Sun, Jun 3, 2018 at 8:43 PM Graham Gill wrote:
> Please see the paste: https://pastebin.com/zBim7Zkx
>
> I'm experimenting with defining UpperBounded and LowerBounded typeclasses.
> An example type belonging to the latter that is not also Bounded would be
> type Natural from Numeric.Natural.
>
> I want to say that if a type is Bounded, then it is also UpperBounded and
> LowerBounded. If a type is both UpperBounded and LowerBounded, then it is
> also Bounded.
>
> To express the constraints, I need FlexibleInstances and
> UndecidableInstances extensions. These allow the module to load into ghci
> (8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
> overlapping instance error if I try to evaluate minBound, maxBound,
> upperBound or lowerBound instantiated to either of the types Foo or Bar.
>
> A solution is to apply the INCOHERENT pragma to the instances at lines 11,
> 14 and 17. Reading over section 10.8.3.6. Overlapping instances in the GHC
> User Guide, I believe I understand. (Is there a better solution?)
>
> In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This
> gives me the following behaviour in ghci:
>
> 1. minBound, maxBound, upperBound and lowerBound instantiated to type
> Foo all function as expected, evaluating to the appropriate lower or upper
> bound.
> 2. upperBound and maxBound instantiated at Bar give overlapping
> instance errors for UpperBounded, as expected.
> 3. lowerBound :: Bar evaluates to C, as expected.
> 4. minBound :: Bar gives an overlapping instance error for
> UpperBounded:
>
> *UpperLowerBounded> minBound :: Bar
>
> :141:1: error:
> • Overlapping instances for UpperBounded Bar
> arising from a use of ‘minBound’
> Matching instances:
> instance [safe] Bounded a => UpperBounded a
> -- Defined at UpperLowerBounded.hs:14:10
> instance [safe] UpperBounded Bar -- Defined at
> UpperLowerBounded.hs:31:10
> • In the expression: minBound :: Bar
> In an equation for ‘it’: it = minBound :: Bar
>
>
> It's #4 that I don't understand. An explanation would be very much
> appreciated. (Also, what's a [safe] instance?)
>
> Regards,
> Graham
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From andreas.roehler at easy-emacs.de Mon Jun 4 07:09:57 2018
From: andreas.roehler at easy-emacs.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=)
Date: Mon, 4 Jun 2018 09:09:57 +0200
Subject: [Haskell-beginners] ghc-8.4.3 at Ubuntu
Message-ID: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
While installing ghc-8.4.3-i386-deb8-linux.tar.xz at Debian8 went
smoothly, can't se how to install ghc-8.4.3 at Ubuntu resp. Xubuntu:
in dir ghc-8.4.3/
./configure
checking for gfind... no
checking for find... /usr/bin/find
checking for sort... /usr/bin/sort
checking for GHC Git commit id... given
51abb1c88b53e2989a2a8c2939ac4abc04bef194
checking for ghc... /usr/bin/ghc
checking version of ghc... 7.10.3
configure: error: GHC version 8.0 or later is required to compile GHC.
Did cabal update
and tried haskell-platform for ubuntu
https://www.haskell.org/platform/linux.html#linux-ubuntu
which seems broken
Tried Haskell-platform from source:
./platform.sh
***
*** Building hptool
***
cabal: unrecognised command: new-build (try --help)
Any help?
Cheers,
Andreas
From jeffbrown.the at gmail.com Mon Jun 4 07:22:23 2018
From: jeffbrown.the at gmail.com (Jeffrey Brown)
Date: Mon, 4 Jun 2018 02:22:23 -0500
Subject: [Haskell-beginners] ghc-8.4.3 at Ubuntu
In-Reply-To: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
References: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
Message-ID:
You could use stack instead of cabal. The most recent nightly stack
snapshots use GHC 8.4.3. Stack has a lot[1] of advantages. One of them is
that you can use a bunch of different versions of GHC at the same time.
Whereas Cabal keeps a global collection of Haskell software, Stack keeps a
bunch of different local ones, while cleverly avoiding wasting memory like
you might expect that to imply. If you have a project that needs old stuff
that's incompatible with new stuff, you're SOL with Cabal but it's no
problem in Stack.
[1]
https://stackoverflow.com/questions/30913145/what-is-the-difference-between-cabal-and-stack
On Mon, Jun 4, 2018 at 2:08 AM Andreas Röhler
wrote:
> While installing ghc-8.4.3-i386-deb8-linux.tar.xz at Debian8 went
> smoothly, can't se how to install ghc-8.4.3 at Ubuntu resp. Xubuntu:
>
>
> in dir ghc-8.4.3/
>
> ./configure
> checking for gfind... no
> checking for find... /usr/bin/find
> checking for sort... /usr/bin/sort
> checking for GHC Git commit id... given
> 51abb1c88b53e2989a2a8c2939ac4abc04bef194
> checking for ghc... /usr/bin/ghc
> checking version of ghc... 7.10.3
> configure: error: GHC version 8.0 or later is required to compile GHC.
>
> Did cabal update
>
> and tried haskell-platform for ubuntu
> https://www.haskell.org/platform/linux.html#linux-ubuntu
>
> which seems broken
>
> Tried Haskell-platform from source:
>
> ./platform.sh
> ***
> *** Building hptool
> ***
> cabal: unrecognised command: new-build (try --help)
>
>
> Any help?
>
> Cheers,
> Andreas
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Jeff Brown | Jeffrey Benjamin Brown
Website | Facebook
| LinkedIn
(spammy, so I often miss
messages here) | Github
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From utprimum at gmail.com Mon Jun 4 07:30:10 2018
From: utprimum at gmail.com (Ut Primum)
Date: Mon, 4 Jun 2018 09:30:10 +0200
Subject: [Haskell-beginners] ghc-8.4.3 at Ubuntu
In-Reply-To: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
References: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
Message-ID:
Hi,
It seems as if you have also another version of GHC installed on your
computer in another directory (usr/bin/ghc), and its version is 7.10.3, and
it is considered the global version.
You could try to use a virtual environment for installing the version 8.4.3
http://hackage.haskell.org/package/hsenv
(I've never tried so I am not sure it works)
Regards
Il lun 4 giu 2018, 09:08 Andreas Röhler ha
scritto:
> While installing ghc-8.4.3-i386-deb8-linux.tar.xz at Debian8 went
> smoothly, can't se how to install ghc-8.4.3 at Ubuntu resp. Xubuntu:
>
>
> in dir ghc-8.4.3/
>
> ./configure
> checking for gfind... no
> checking for find... /usr/bin/find
> checking for sort... /usr/bin/sort
> checking for GHC Git commit id... given
> 51abb1c88b53e2989a2a8c2939ac4abc04bef194
> checking for ghc... /usr/bin/ghc
> checking version of ghc... 7.10.3
> configure: error: GHC version 8.0 or later is required to compile GHC.
>
> Did cabal update
>
> and tried haskell-platform for ubuntu
> https://www.haskell.org/platform/linux.html#linux-ubuntu
>
> which seems broken
>
> Tried Haskell-platform from source:
>
> ./platform.sh
> ***
> *** Building hptool
> ***
> cabal: unrecognised command: new-build (try --help)
>
>
> Any help?
>
> Cheers,
> Andreas
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From andreas.roehler at easy-emacs.de Mon Jun 4 09:22:15 2018
From: andreas.roehler at easy-emacs.de (=?UTF-8?Q?Andreas_R=c3=b6hler?=)
Date: Mon, 4 Jun 2018 11:22:15 +0200
Subject: [Haskell-beginners] ghc-8.4.3 at Ubuntu
In-Reply-To:
References: <8f53b1b9-842a-b15e-0670-9b6f04e63cb9@easy-emacs.de>
Message-ID:
Thanks all!
Will try hsenv.
Meanwhile recipe found here was succesful:
https://www.reddit.com/r/haskell/comments/5jsyr0/announce_ghc_802_release_candidate_2/
Did
sudo apt-add-repository ppa:hvr/ghc
sudo apt update
sudo apt install ghc-8.0.2 cabal-install-1.24
added /opt/ghc/bin to $PATH
Configure done so and make is running...
On 04.06.2018 09:30, Ut Primum wrote:
> Hi,
> It seems as if you have also another version of GHC installed on your
> computer in another directory (usr/bin/ghc), and its version is 7.10.3,
> and it is considered the global version.
> You could try to use a virtual environment for installing the version 8.4.3
>
> http://hackage.haskell.org/package/hsenv
>
> (I've never tried so I am not sure it works)
> Regards
>
> Il lun 4 giu 2018, 09:08 Andreas Röhler > ha scritto:
>
> While installing ghc-8.4.3-i386-deb8-linux.tar.xz at Debian8 went
> smoothly, can't se how to install ghc-8.4.3 at Ubuntu resp. Xubuntu:
>
>
> in dir ghc-8.4.3/
>
> ./configure
> checking for gfind... no
> checking for find... /usr/bin/find
> checking for sort... /usr/bin/sort
> checking for GHC Git commit id... given
> 51abb1c88b53e2989a2a8c2939ac4abc04bef194
> checking for ghc... /usr/bin/ghc
> checking version of ghc... 7.10.3
> configure: error: GHC version 8.0 or later is required to compile GHC.
>
> Did cabal update
>
> and tried haskell-platform for ubuntu
> https://www.haskell.org/platform/linux.html#linux-ubuntu
>
> which seems broken
>
> Tried Haskell-platform from source:
>
> ./platform.sh
> ***
> *** Building hptool
> ***
> cabal: unrecognised command: new-build (try --help)
>
>
> Any help?
>
> Cheers,
> Andreas
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
From toad3k at gmail.com Mon Jun 4 12:54:28 2018
From: toad3k at gmail.com (David McBride)
Date: Mon, 4 Jun 2018 08:54:28 -0400
Subject: [Haskell-beginners] incoherent instance question
In-Reply-To:
References:
Message-ID:
This is a common thing that people try to do. I want class A to apply to
any type in which class B already applies. It seems to mimic what would
work in object oriented programming and it is hard to see at first why it
doesn't work in haskell.
Just remember that they are "typeclasses", not "classclasses". When you
write
class Foo a where foo :: ...
instance Show a => Foo a where foo = something
Everything seems fine, but then you could write additional classes like this
instance Read a => Foo a where foo = something_else
And what if you had a type that is both a Read and Show, like Int? Now
there are two different things it could do -- something and
something_else. How to decide? Based on order? But then the behavior of
the program could dramatically change based on the import order.
I would advise you to treat Bounded, UpperBounded, and LowerBounded to be
separate properties and define them on all types explicitly rather than
trying to obtain instances for free.
On Sun, Jun 3, 2018 at 11:42 PM, Graham Gill wrote:
> Please see the paste: https://pastebin.com/zBim7Zkx
>
> I'm experimenting with defining UpperBounded and LowerBounded typeclasses.
> An example type belonging to the latter that is not also Bounded would be
> type Natural from Numeric.Natural.
>
> I want to say that if a type is Bounded, then it is also UpperBounded and
> LowerBounded. If a type is both UpperBounded and LowerBounded, then it is
> also Bounded.
>
> To express the constraints, I need FlexibleInstances and
> UndecidableInstances extensions. These allow the module to load into ghci
> (8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
> overlapping instance error if I try to evaluate minBound, maxBound,
> upperBound or lowerBound instantiated to either of the types Foo or Bar.
>
> A solution is to apply the INCOHERENT pragma to the instances at lines 11,
> 14 and 17. Reading over section 10.8.3.6. Overlapping instances in the GHC
> User Guide, I believe I understand. (Is there a better solution?)
>
> In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This
> gives me the following behaviour in ghci:
>
> 1. minBound, maxBound, upperBound and lowerBound instantiated to type
> Foo all function as expected, evaluating to the appropriate lower or upper
> bound.
> 2. upperBound and maxBound instantiated at Bar give overlapping
> instance errors for UpperBounded, as expected.
> 3. lowerBound :: Bar evaluates to C, as expected.
> 4. minBound :: Bar gives an overlapping instance error for
> UpperBounded:
>
> *UpperLowerBounded> minBound :: Bar
>
> :141:1: error:
> • Overlapping instances for UpperBounded Bar
> arising from a use of ‘minBound’
> Matching instances:
> instance [safe] Bounded a => UpperBounded a
> -- Defined at UpperLowerBounded.hs:14:10
> instance [safe] UpperBounded Bar -- Defined at
> UpperLowerBounded.hs:31:10
> • In the expression: minBound :: Bar
> In an equation for ‘it’: it = minBound :: Bar
>
>
> It's #4 that I don't understand. An explanation would be very much
> appreciated. (Also, what's a [safe] instance?)
>
> Regards,
> Graham
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From leiva.steven at gmail.com Tue Jun 5 19:05:00 2018
From: leiva.steven at gmail.com (Steven Leiva)
Date: Tue, 5 Jun 2018 14:05:00 -0500
Subject: [Haskell-beginners] How to get IO String from
Network.Socket.ByteString.recv method
In-Reply-To:
References: <1643328860.3250152.1526802753434.ref@mail.yahoo.com>
<1643328860.3250152.1526802753434@mail.yahoo.com>
Message-ID:
A bit late to the party, but to build on the previous answer, you're going
to run into the same problem with the Text data type, which has both a lazy
variant and a strict (?) variant.
The functions to convert from/to the strict/lazy variant are usually in the
lazy module:
*Data.Text.Lazy.toStrict* and *Data.Text.Lazy.fromStrict*.
*Data.ByteString.Lazy.toStrict* and *Data.ByteString.Lazy.toStrict*.
It's a common use-case to want to save the Text / ByteString to a file, and
in those cases you can find helper functions such as
*Data.ByteString.Lazy.writeFile*.
On Sun, May 20, 2018 at 6:56 PM, Daniel Bergey wrote:
> Network.Socket.ByteString.recv uses the strict ByteString from
> Data.ByteString, not the lazy one from Data.ByteString.Lazy. So you
> want the `unpack` from Data.ByteString.Char8, rather than
> Data.ByteString.Lazy.Char8.
>
> I never remember which functions return strict or lazy ByteString. I
> find the easiest way to check is to open the online docs and see where
> the `ByteString` link points:
>
> https://hackage.haskell.org/package/network-2.7.0.0/docs/
> Network-Socket-ByteString.html#v:recv
>
> points to:
>
> https://hackage.haskell.org/package/bytestring-0.10.8.2/
> docs/Data-ByteString.html#t:ByteString
>
> hope this helps,
> bergey
>
> On 2018-05-20 at 07:52, Dinesh Amerasekara wrote:
> > Hi,
> >
> > I am unable to compile the below code.
> >
> > import Network.Socket hiding(recv)
> > import Network.Socket.ByteString as S (recv)
> > import qualified Data.ByteString.Lazy.Char8 as Char8
> >
> > getMessage :: Socket -> IO String
> > getMessage sock = Char8.unpack <$> S.recv sock 8888
> >
> > It gives the below error.
> >
> > Couldn't match type ‘Data.ByteString.Internal.ByteString’
> > with ‘ByteString’
> > NB: ‘ByteString’ is defined in ‘Data.ByteString.Lazy.Internal’
> > ‘Data.ByteString.Internal.ByteString’
> > is defined in ‘Data.ByteString.Internal’
> > Expected type: IO ByteString
> > Actual type: IO Data.ByteString.Internal.ByteString
> >
> > In the second argument of ‘(<$>)’, namely ‘recv sock 8888’
> > In the expression: unpack <$> recv sock 8888
> > In an equation for ‘getMsg’:
> > getMsg sock = unpack <$> recv sock 8888
> >
> > Can somebody tell me how I can return the IO String using
> > Network.Socket.ByteString.recv?
> >
> > Best Regards,
> > Dinesh.
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Steven Leiva
305.528.6038
leiva.steven at gmail.com
http://www.linkedin.com/in/stevenleiva
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From math.simplex at gmail.com Sat Jun 9 01:12:46 2018
From: math.simplex at gmail.com (Graham Gill)
Date: Fri, 8 Jun 2018 21:12:46 -0400
Subject: [Haskell-beginners] incoherent instance question
In-Reply-To:
References:
Message-ID:
Thank you Alex for that comprehensive answer. That's very helpful. I'd
considered a newtype, but I really wondered what prevented me from using or
was bad about the approach I described.
Regards,
Graham
On 04-Jun-2018 1:10 AM, Alex Rozenshteyn wrote:
I want to say that if a type is Bounded, then it is also UpperBounded and
> LowerBounded.
Seems reasonable
> If a type is both UpperBounded and LowerBounded, then it is also Bounded.
Danger Will Robinson. Nothing stops modules (realistically, in two
different library) from defining incompatible UpperBounded and LowerBounded
instances; for example, I may want `lowerBound :: Bool` to be `True`, while
you may want `upperBound :: Bool` to be `True`; when they are both
imported, bad things can happen. In this case, requiring an Ord constraint
and adding documentation on lawful instances would pretty much solve the
problem, but in general, this is an unwise thing to do.
Specifically, it is usually a bad idea to have a type class that should
have an instance for a type whenever that type has instances of some
combination of other classes.
Three ways around it:
- Use a newtype wrapper: define `newtype LowerUpperBounded` and have the
instance be `(LowerBounded a, UpperBounded a) => Bounded (LowerUpperBounded
a)`
- Defer instance definition to concrete types: if you know that a
specific type has both super-instances, you can explicitly instantiate it
at the sub-instance
- Define a constraint alias: (this requires some more advanced
extensions, so I'm only mentioning it as an option for completeness' sake)
Using `ConstraintKinds`, you can define `type Bounded a = (LowerBounded a,
UpperBounded a)`; this makes the two definitions synonymous.
To your immediate question, I *think* what's happening is that when you're
trying to do `minBound :: Bar` it looks for an instance `Bounded Bar` and
finds the unique one; then it needs to satisfy the constraints, so it looks
for `LowerBounded Bar` and `UpperBounded Bar`, the latter of which has two
possible instances, neither of which is marked overlapping or incoherent.
You'll notice that if you use `-fdefer-type-errors` you will be able to get
the `minBound` of `Bar` (though for some reason you need to bind it to a
variable), but not the `maxBound`.
You should also note that if you use the `OVERLAPPABLE` pragma rather than
the `INCOHERENT` one, you get the same results, and that is generally
considered less risky.
On Sun, Jun 3, 2018 at 8:43 PM Graham Gill wrote:
> Please see the paste: https://pastebin.com/zBim7Zkx
>
> I'm experimenting with defining UpperBounded and LowerBounded typeclasses.
> An example type belonging to the latter that is not also Bounded would be
> type Natural from Numeric.Natural.
>
> I want to say that if a type is Bounded, then it is also UpperBounded and
> LowerBounded. If a type is both UpperBounded and LowerBounded, then it is
> also Bounded.
>
> To express the constraints, I need FlexibleInstances and
> UndecidableInstances extensions. These allow the module to load into ghci
> (8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
> overlapping instance error if I try to evaluate minBound, maxBound,
> upperBound or lowerBound instantiated to either of the types Foo or Bar.
>
> A solution is to apply the INCOHERENT pragma to the instances at lines 11,
> 14 and 17. Reading over section 10.8.3.6. Overlapping instances in the GHC
> User Guide, I believe I understand. (Is there a better solution?)
>
> In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This
> gives me the following behaviour in ghci:
>
> 1. minBound, maxBound, upperBound and lowerBound instantiated to type
> Foo all function as expected, evaluating to the appropriate lower or upper
> bound.
> 2. upperBound and maxBound instantiated at Bar give overlapping
> instance errors for UpperBounded, as expected.
> 3. lowerBound :: Bar evaluates to C, as expected.
> 4. minBound :: Bar gives an overlapping instance error for
> UpperBounded:
>
> *UpperLowerBounded> minBound :: Bar
>
> :141:1: error:
> • Overlapping instances for UpperBounded Bar
> arising from a use of ‘minBound’
> Matching instances:
> instance [safe] Bounded a => UpperBounded a
> -- Defined at UpperLowerBounded.hs:14:10
> instance [safe] UpperBounded Bar -- Defined at
> UpperLowerBounded.hs:31:10
> • In the expression: minBound :: Bar
> In an equation for ‘it’: it = minBound :: Bar
>
>
> It's #4 that I don't understand. An explanation would be very much
> appreciated. (Also, what's a [safe] instance?)
>
> Regards,
> Graham
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
_______________________________________________
Beginners mailing
listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From math.simplex at gmail.com Sat Jun 9 01:24:57 2018
From: math.simplex at gmail.com (Graham Gill)
Date: Fri, 8 Jun 2018 21:24:57 -0400
Subject: [Haskell-beginners] incoherent instance question
In-Reply-To:
References:
Message-ID:
Thanks for the explanation David. The problem is clear from your
description, and when you *really* do want to do it anyway I guess that's
what the INCOHERENT and OVERLAPS/OVERLAPPING pragmas are for, to help you
control the types.
Just remember that they are "typeclasses", not "classclasses".
Actually I wasn't thinking in terms of "classclasses", instead, of
mathematical equivalences. A set of reals is bounded iff it is both upper
and lower bounded. I wanted to try to express that in types, and wondered
if I could do it without resorting to asymmetrical syntax (the newtype
suggestion).
Regards,
Graham
On Mon, Jun 4, 2018 at 8:54 AM David McBride wrote:
> This is a common thing that people try to do. I want class A to apply to
> any type in which class B already applies. It seems to mimic what would
> work in object oriented programming and it is hard to see at first why it
> doesn't work in haskell.
>
> Just remember that they are "typeclasses", not "classclasses". When you
> write
>
> class Foo a where foo :: ...
> instance Show a => Foo a where foo = something
>
> Everything seems fine, but then you could write additional classes like
> this
>
> instance Read a => Foo a where foo = something_else
>
> And what if you had a type that is both a Read and Show, like Int? Now
> there are two different things it could do -- something and
> something_else. How to decide? Based on order? But then the behavior of
> the program could dramatically change based on the import order.
>
> I would advise you to treat Bounded, UpperBounded, and LowerBounded to be
> separate properties and define them on all types explicitly rather than
> trying to obtain instances for free.
>
> On Sun, Jun 3, 2018 at 11:42 PM, Graham Gill
> wrote:
>
>> Please see the paste: https://pastebin.com/zBim7Zkx
>>
>> I'm experimenting with defining UpperBounded and LowerBounded
>> typeclasses. An example type belonging to the latter that is not also
>> Bounded would be type Natural from Numeric.Natural.
>>
>> I want to say that if a type is Bounded, then it is also UpperBounded and
>> LowerBounded. If a type is both UpperBounded and LowerBounded, then it is
>> also Bounded.
>>
>> To express the constraints, I need FlexibleInstances and
>> UndecidableInstances extensions. These allow the module to load into ghci
>> (8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
>> overlapping instance error if I try to evaluate minBound, maxBound,
>> upperBound or lowerBound instantiated to either of the types Foo or Bar.
>>
>> A solution is to apply the INCOHERENT pragma to the instances at lines
>> 11, 14 and 17. Reading over section 10.8.3.6. Overlapping instances in the
>> GHC User Guide, I believe I understand. (Is there a better solution?)
>>
>> In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This
>> gives me the following behaviour in ghci:
>>
>> 1. minBound, maxBound, upperBound and lowerBound instantiated to type
>> Foo all function as expected, evaluating to the appropriate lower or upper
>> bound.
>> 2. upperBound and maxBound instantiated at Bar give overlapping
>> instance errors for UpperBounded, as expected.
>> 3. lowerBound :: Bar evaluates to C, as expected.
>> 4. minBound :: Bar gives an overlapping instance error for
>> UpperBounded:
>>
>> *UpperLowerBounded> minBound :: Bar
>>
>> :141:1: error:
>> • Overlapping instances for UpperBounded Bar
>> arising from a use of ‘minBound’
>> Matching instances:
>> instance [safe] Bounded a => UpperBounded a
>> -- Defined at UpperLowerBounded.hs:14:10
>> instance [safe] UpperBounded Bar -- Defined at
>> UpperLowerBounded.hs:31:10
>> • In the expression: minBound :: Bar
>> In an equation for ‘it’: it = minBound :: Bar
>>
>>
>> It's #4 that I don't understand. An explanation would be very much
>> appreciated. (Also, what's a [safe] instance?)
>>
>> Regards,
>> Graham
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From rpglover64 at gmail.com Sat Jun 9 01:36:32 2018
From: rpglover64 at gmail.com (Alex Rozenshteyn)
Date: Fri, 8 Jun 2018 18:36:32 -0700
Subject: [Haskell-beginners] incoherent instance question
In-Reply-To:
References:
Message-ID:
>
> mathematical equivalences
Yeah... Unfortunately, type classes aren't good at those. They're good for
necessary conditions, and you can make them work for necessary and
sufficient conditions, but only if you control the class in question. One
major problem in your attempt is that you're not defining Bounded yourself,
so you can't define necessary conditions (since those would have to be part
of the class). If you controlled Bounded, you could do this:
class UpperBounded a where ...
class LowerBounded a where ...
class (UpperBounded a, LowerBounded a) => Bounded a -- This is the
"necessary" part; notice no "..."
instance (UpperBounded a, LowerBounded a) => Bounded a -- This is the
"sufficient" part
You'd need to turn on some extensions (UndecidableInstances and
FlexibleContexts, IIRC).
On Fri, Jun 8, 2018 at 6:24 PM, Graham Gill wrote:
> Thanks for the explanation David. The problem is clear from your
> description, and when you *really* do want to do it anyway I guess that's
> what the INCOHERENT and OVERLAPS/OVERLAPPING pragmas are for, to help you
> control the types.
>
> Just remember that they are "typeclasses", not "classclasses".
>
>
> Actually I wasn't thinking in terms of "classclasses", instead, of
> mathematical equivalences. A set of reals is bounded iff it is both upper
> and lower bounded. I wanted to try to express that in types, and wondered
> if I could do it without resorting to asymmetrical syntax (the newtype
> suggestion).
>
> Regards,
> Graham
>
>
> On Mon, Jun 4, 2018 at 8:54 AM David McBride wrote:
>
>> This is a common thing that people try to do. I want class A to apply to
>> any type in which class B already applies. It seems to mimic what would
>> work in object oriented programming and it is hard to see at first why it
>> doesn't work in haskell.
>>
>> Just remember that they are "typeclasses", not "classclasses". When you
>> write
>>
>> class Foo a where foo :: ...
>> instance Show a => Foo a where foo = something
>>
>> Everything seems fine, but then you could write additional classes like
>> this
>>
>> instance Read a => Foo a where foo = something_else
>>
>> And what if you had a type that is both a Read and Show, like Int? Now
>> there are two different things it could do -- something and
>> something_else. How to decide? Based on order? But then the behavior of
>> the program could dramatically change based on the import order.
>>
>> I would advise you to treat Bounded, UpperBounded, and LowerBounded to be
>> separate properties and define them on all types explicitly rather than
>> trying to obtain instances for free.
>>
>> On Sun, Jun 3, 2018 at 11:42 PM, Graham Gill
>> wrote:
>>
>>> Please see the paste: https://pastebin.com/zBim7Zkx
>>>
>>> I'm experimenting with defining UpperBounded and LowerBounded
>>> typeclasses. An example type belonging to the latter that is not also
>>> Bounded would be type Natural from Numeric.Natural.
>>>
>>> I want to say that if a type is Bounded, then it is also UpperBounded
>>> and LowerBounded. If a type is both UpperBounded and LowerBounded, then it
>>> is also Bounded.
>>>
>>> To express the constraints, I need FlexibleInstances and
>>> UndecidableInstances extensions. These allow the module to load into ghci
>>> (8.4.2) with only a warning, but, without the INCOHERENT pragmas, I get an
>>> overlapping instance error if I try to evaluate minBound, maxBound,
>>> upperBound or lowerBound instantiated to either of the types Foo or Bar.
>>>
>>> A solution is to apply the INCOHERENT pragma to the instances at lines
>>> 11, 14 and 17. Reading over section 10.8.3.6. Overlapping instances in the
>>> GHC User Guide, I believe I understand. (Is there a better solution?)
>>>
>>> In the paste, I have INCOHERENT pragmas only at lines 11 and 17. This
>>> gives me the following behaviour in ghci:
>>>
>>> 1. minBound, maxBound, upperBound and lowerBound instantiated to
>>> type Foo all function as expected, evaluating to the appropriate lower or
>>> upper bound.
>>> 2. upperBound and maxBound instantiated at Bar give overlapping
>>> instance errors for UpperBounded, as expected.
>>> 3. lowerBound :: Bar evaluates to C, as expected.
>>> 4. minBound :: Bar gives an overlapping instance error for
>>> UpperBounded:
>>>
>>> *UpperLowerBounded> minBound :: Bar
>>>
>>> :141:1: error:
>>> • Overlapping instances for UpperBounded Bar
>>> arising from a use of ‘minBound’
>>> Matching instances:
>>> instance [safe] Bounded a => UpperBounded a
>>> -- Defined at UpperLowerBounded.hs:14:10
>>> instance [safe] UpperBounded Bar -- Defined at
>>> UpperLowerBounded.hs:31:10
>>> • In the expression: minBound :: Bar
>>> In an equation for ‘it’: it = minBound :: Bar
>>>
>>>
>>> It's #4 that I don't understand. An explanation would be very much
>>> appreciated. (Also, what's a [safe] instance?)
>>>
>>> Regards,
>>> Graham
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From sourabhsihag16 at gmail.com Sat Jun 9 03:03:54 2018
From: sourabhsihag16 at gmail.com (Saurabh Sihag)
Date: Sat, 9 Jun 2018 08:33:54 +0530
Subject: [Haskell-beginners] How to start Haskell
Message-ID:
Hi all,
I am a newbie in Haskell and I am interested to explore Haskell. Kindly
help me from where I start. I have prior experience in Python and C.
Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From fa-ml at ariis.it Sat Jun 9 10:13:07 2018
From: fa-ml at ariis.it (Francesco Ariis)
Date: Sat, 9 Jun 2018 12:13:07 +0200
Subject: [Haskell-beginners] How to start Haskell
In-Reply-To:
References:
Message-ID: <20180609101307.lufm734goo54r3gl@x60s.casa>
On Sat, Jun 09, 2018 at 08:33:54AM +0530, Saurabh Sihag wrote:
> Hi all,
> I am a newbie in Haskell and I am interested to explore Haskell. Kindly
> help me from where I start. I have prior experience in Python and C.
> Thank you.
Hello Saurabh,
CIS194 [1] is what you need! Free, thorough, full of exercises
-F
[1] http://www.seas.upenn.edu/~cis194/fall16/
From marco.turchetto.mt at gmail.com Tue Jun 12 16:12:05 2018
From: marco.turchetto.mt at gmail.com (Marco Turchetto)
Date: Tue, 12 Jun 2018 18:12:05 +0200
Subject: [Haskell-beginners] fmap composition
Message-ID:
I'm reading the "Haskell programming" book and in chapter 16 about functors
they combine two "fmap" with the "(.)" function.
I really don't understand how the type of "fmap . fmap" is "(Functor f2,
Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
The thing that really freaks me out is that I thought that "(.)" arguments
are ONLY two unary function.
Maybe there is some curring magic underline, there is someone that can
explain to me how the type of "fmap . fmap" is derived from the type of
"fmap" and "(.)"?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From utprimum at gmail.com Tue Jun 12 17:35:30 2018
From: utprimum at gmail.com (Ut Primum)
Date: Tue, 12 Jun 2018 19:35:30 +0200
Subject: [Haskell-beginners] fmap composition
In-Reply-To:
References:
Message-ID:
Hi,
as you probably know, fmap ha type
fmap :: Functor f => (a -> b) -> f a -> f b
So, you can see fmap as a unary funcrion that takes an argument of type
(a->b) and returns a result of type (f a -> f b).
For example, if you define
identity x = x
then
fmap identity :: Functor f => f b -> f b
(here a = b because identity :: p -> p )
Now, the type of (.) is;
(.) :: (b -> c) -> (a -> b) -> (a -> c)
if you write fmap . fmap, in general (a priori) the type of the fmaps
could be
FIRSTFMAP fmap :: Functor f1 => (d -> e) -> f1 d -> f1 e
SECONDFMAP fmap :: Functor f2 => (g -> h) -> f2 g -> f2 h
let's see if there must be some bonds between types d,e,g,h, due to the
type of (.)
(b -> c) = FIRSTFMAP (the first argument of (.) )
(a -> b) = SECONDFMAP (the second argument of (.) )
so, we have (I'll not write "Functor f1" or "Functor f2", we know f1 and f2
are functors)
b = (d -> e)
c = (f1 d -> f1 e)
a = (g -> h)
b = (f2 g -> f2 h)
now, it must be b=b, so the type (d -> e) must be the same type of (f2 g ->
f2 h)
So
d = f2 g
e = f2 h
The result of fmap . fmap, will be of type (a -> c) that is
(g -> h) -> (f1 d -> f1 e) = (g -> h) -> f1 d -> f1 e
that, remebering the conditions on d and e, is
(g -> h) -> f1 (f2 g) -> f1 (f2 h)
which is the type you found on the book
(you only need to add that f1, f2 are Functors, and the names of f and g
can of course be replaced with a and b)
Cheers,
Ut
2018-06-12 18:12 GMT+02:00 Marco Turchetto :
> I'm reading the "Haskell programming" book and in chapter 16 about
> functors they combine two "fmap" with the "(.)" function.
> I really don't understand how the type of "fmap . fmap" is "(Functor f2,
> Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
>
> The thing that really freaks me out is that I thought that "(.)" arguments
> are ONLY two unary function.
> Maybe there is some curring magic underline, there is someone that can
> explain to me how the type of "fmap . fmap" is derived from the type of
> "fmap" and "(.)"?
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From marco.turchetto.mt at gmail.com Wed Jun 13 07:38:40 2018
From: marco.turchetto.mt at gmail.com (Marco Turchetto)
Date: Wed, 13 Jun 2018 09:38:40 +0200
Subject: [Haskell-beginners] fmap composition
In-Reply-To:
References:
Message-ID:
It's all clear as day.
Thanks
On Tue, 12 Jun 2018 at 19:35 Ut Primum wrote:
> Hi,
> as you probably know, fmap ha type
> fmap :: Functor f => (a -> b) -> f a -> f b
> So, you can see fmap as a unary funcrion that takes an argument of type
> (a->b) and returns a result of type (f a -> f b).
>
> For example, if you define
> identity x = x
> then
> fmap identity :: Functor f => f b -> f b
> (here a = b because identity :: p -> p )
>
> Now, the type of (.) is;
> (.) :: (b -> c) -> (a -> b) -> (a -> c)
>
> if you write fmap . fmap, in general (a priori) the type of the fmaps
> could be
> FIRSTFMAP fmap :: Functor f1 => (d -> e) -> f1 d -> f1 e
> SECONDFMAP fmap :: Functor f2 => (g -> h) -> f2 g -> f2 h
>
> let's see if there must be some bonds between types d,e,g,h, due to the
> type of (.)
>
> (b -> c) = FIRSTFMAP (the first argument of (.) )
> (a -> b) = SECONDFMAP (the second argument of (.) )
>
> so, we have (I'll not write "Functor f1" or "Functor f2", we know f1 and
> f2 are functors)
>
> b = (d -> e)
> c = (f1 d -> f1 e)
> a = (g -> h)
> b = (f2 g -> f2 h)
>
> now, it must be b=b, so the type (d -> e) must be the same type of (f2 g
> -> f2 h)
> So
> d = f2 g
> e = f2 h
>
> The result of fmap . fmap, will be of type (a -> c) that is
> (g -> h) -> (f1 d -> f1 e) = (g -> h) -> f1 d -> f1 e
> that, remebering the conditions on d and e, is
> (g -> h) -> f1 (f2 g) -> f1 (f2 h)
>
> which is the type you found on the book
> (you only need to add that f1, f2 are Functors, and the names of f and g
> can of course be replaced with a and b)
>
> Cheers,
> Ut
>
> 2018-06-12 18:12 GMT+02:00 Marco Turchetto :
>
>> I'm reading the "Haskell programming" book and in chapter 16 about
>> functors they combine two "fmap" with the "(.)" function.
>> I really don't understand how the type of "fmap . fmap" is "(Functor f2,
>> Functor f1) => (a -> b) -> f1 (f2 a) -> f1 (f2 b)".
>>
>> The thing that really freaks me out is that I thought that "(.)"
>> arguments are ONLY two unary function.
>> Maybe there is some curring magic underline, there is someone that can
>> explain to me how the type of "fmap . fmap" is derived from the type of
>> "fmap" and "(.)"?
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From sylvester.hazel at googlemail.com Sat Jun 16 20:23:36 2018
From: sylvester.hazel at googlemail.com (Sylvester Hazel)
Date: Sat, 16 Jun 2018 22:23:36 +0200
Subject: [Haskell-beginners] life with Hutton 2ed
Message-ID:
I wonder why life/10.8 runs nonsensically on my PC even with
Language.Haskell.HsColour.ANSI import?
These cls and goto reappear in 11.7 that spoil the pleasure of
understanding.
Also putGrid/11.4 is unintuitive backsword engineering concoction that
teaches nothing, while it can be very intuitively written: putGrid g =
sequence_ [putStrLn j| j<-weave [' ','|',' ','|',' '] (interleave
(replicate 6 '-') [(interleave '|' i)| i<-g])]
interleave :: a->[a]->[a]
interleave x [] = []
interleave x [y] = [y]
interleave x (y:ys)= y:x:interleave x ys
weave :: a->[a]->[a]
weave x [] = [x]
weave x [y] = x:[y,x]
weave x (y:ys)= x:y:weave x ys
Prelude> putGrid [[' ','O','O'],['O','X','O'],['X','X','X']]
| |
|O|O
| |
------
| |
O|X|O
| |
------
| |
X|X|X
| |
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From 50295 at web.de Sun Jun 17 13:24:56 2018
From: 50295 at web.de (Olumide)
Date: Sun, 17 Jun 2018 14:24:56 +0100
Subject: [Haskell-beginners] Difficulty understanding how to use filterM to
compute powerset
Message-ID: <41001987-f04c-6b2c-e291-4f3f021aa0f0@web.de>
Dear List,
I'm trying to apply the following definition of filterM (from Brent
Yorgey's blog
https://byorgey.wordpress.com/2007/06/26/deducing-code-from-types-filterm/)
import Control.Monad -- for liftM
filterM' :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
filterM' p [] = return []
filterM' p (x:xs) =
let rest = filterM' p xs in
do b <- p x
if b then liftM (x:) rest
else rest
in order to understand how filterM can be used to compute the power set
of a list, as follows
filterM' (const [False,True]) [1,2,3]
Where p in the filterM' is (const [False,True]). What confuses me is
that p x in filterM'. Based on my very limited understanding p x returns
b = [False, True]. How b be tested in the subsequent if-statement if it
is indeed a list? What am I getting wrong?
Regards,
- Olumide
From toad3k at gmail.com Sun Jun 17 19:02:47 2018
From: toad3k at gmail.com (David McBride)
Date: Sun, 17 Jun 2018 15:02:47 -0400
Subject: [Haskell-beginners] Difficulty understanding how to use filterM
to compute powerset
In-Reply-To: <41001987-f04c-6b2c-e291-4f3f021aa0f0@web.de>
References: <41001987-f04c-6b2c-e291-4f3f021aa0f0@web.de>
Message-ID:
You are right, that the predicate in this case the argument is ignored. In
fact you can rewrite it and it would work the same.
filterM2' :: (Monad m) => (m Bool) -> [a] -> m [a]
filterM2' p [] = return []
filterM2' p (x:xs) =
let rest = filterM2' p xs in
do b <- p
if b then liftM (x:) rest
else rest
filterM2' [False,True] [1,2,3]
As for how this works, remember that lists are Monads and their instance
makes them work like list comprehensions. Consider the following.
test2 :: [(Int,Int)]
test2 = do
x <- [1,2]
y <- [3,4]
return (x,y)
[(1,3),(1,4),(2,3),(2,4)]
test3 :: [String]
test3 = do
x <- [True, False, True]
if x
then ["x was true"]
else ["x was false"]
["x was true","x was false", "x was true"]
So the List Monad instance pairs each element with every other element,
returning a list of every case. In filterM's case, it checks each x and
based on that does something slightly different. In fact what it is doing
is giving you two cases, one where x is there and one where it isn't, then
running the same function on the remaining elements once for each of those
two cases to fill in the remaining cases, appending all the results
together. In my opinion it is easier to understand by just playing with it.
filterM2' [True,True] [1,2]
[[1,2],[1,2],[1,2],[1,2]]
filterM2' [True,False] [1,2]
[[1,2],[1],[2],[]]
filterM2' [False,True] [1,2]
[[],[2],[1],[1,2]]
filterM2' [False,False] [1,2]
[[],[],[],[]]
On Sun, Jun 17, 2018 at 9:24 AM, Olumide <50295 at web.de> wrote:
> Dear List,
>
> I'm trying to apply the following definition of filterM (from Brent
> Yorgey's blog https://byorgey.wordpress.com/2007/06/26/deducing-code-from-
> types-filterm/)
>
> import Control.Monad -- for liftM
>
> filterM' :: (Monad m) => (a -> m Bool) -> [a] -> m [a]
> filterM' p [] = return []
> filterM' p (x:xs) =
> let rest = filterM' p xs in
> do b <- p x
> if b then liftM (x:) rest
> else rest
>
> in order to understand how filterM can be used to compute the power set of
> a list, as follows
>
> filterM' (const [False,True]) [1,2,3]
>
> Where p in the filterM' is (const [False,True]). What confuses me is that
> p x in filterM'. Based on my very limited understanding p x returns b =
> [False, True]. How b be tested in the subsequent if-statement if it is
> indeed a list? What am I getting wrong?
>
> Regards,
>
> - Olumide
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From aquagnu at gmail.com Wed Jun 20 06:25:20 2018
From: aquagnu at gmail.com (PY)
Date: Wed, 20 Jun 2018 09:25:20 +0300
Subject: [Haskell-beginners] How to define macro var with stack/cabal/etc?
Message-ID: <83598e9c-172c-b981-f582-830a234d8cb7@gmail.com>
Hello all,
I'm using conditional compilation:
#ifdef BLAH
blahBlah
#endif
And I want to define BLAN, but no in *.hs file. For example, with
`stack` option, in yaml file, in cabal file, in environment variable...
How can I do it? For example, `stack -DBLAH=1 build` or something else.
What are the options?
===
Best regards, Paul
From kolsrud at gmail.com Wed Jun 20 15:11:01 2018
From: kolsrud at gmail.com (=?UTF-8?Q?=C3=98ystein_Kolsrud?=)
Date: Wed, 20 Jun 2018 17:11:01 +0200
Subject: [Haskell-beginners] How to start Haskell
In-Reply-To: <20180609101307.lufm734goo54r3gl@x60s.casa>
References:
<20180609101307.lufm734goo54r3gl@x60s.casa>
Message-ID:
I did this presentation a couple of years ago. It could serve as a quick
introduction.
https://www.youtube.com/watch?v=I2tMmsZC1ZU
On Sat, Jun 9, 2018 at 12:13 PM, Francesco Ariis wrote:
> On Sat, Jun 09, 2018 at 08:33:54AM +0530, Saurabh Sihag wrote:
> > Hi all,
> > I am a newbie in Haskell and I am interested to explore Haskell.
> Kindly
> > help me from where I start. I have prior experience in Python and C.
> > Thank you.
>
> Hello Saurabh,
> CIS194 [1] is what you need! Free, thorough, full of exercises
> -F
>
> [1] http://www.seas.upenn.edu/~cis194/fall16/
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Mvh Øystein Kolsrud
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From akaberto at gmail.com Wed Jun 20 15:10:50 2018
From: akaberto at gmail.com (akash g)
Date: Wed, 20 Jun 2018 11:10:50 -0400
Subject: [Haskell-beginners] How to start Haskell
In-Reply-To:
References:
<20180609101307.lufm734goo54r3gl@x60s.casa>
Message-ID:
Try this : http://www.scs.stanford.edu/16wi-cs240h/
On Wed, Jun 20, 2018, 11:11 Øystein Kolsrud wrote:
> I did this presentation a couple of years ago. It could serve as a quick
> introduction.
>
> https://www.youtube.com/watch?v=I2tMmsZC1ZU
>
>
> On Sat, Jun 9, 2018 at 12:13 PM, Francesco Ariis wrote:
>
>> On Sat, Jun 09, 2018 at 08:33:54AM +0530, Saurabh Sihag wrote:
>> > Hi all,
>> > I am a newbie in Haskell and I am interested to explore Haskell.
>> Kindly
>> > help me from where I start. I have prior experience in Python and C.
>> > Thank you.
>>
>> Hello Saurabh,
>> CIS194 [1] is what you need! Free, thorough, full of exercises
>> -F
>>
>> [1] http://www.seas.upenn.edu/~cis194/fall16/
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> --
> Mvh Øystein Kolsrud
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: