Send Beginners mailing list submissions to
[email protected]
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
[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. Re: Data constraint? (Francesco Ariis)
2. Re: Data constraint? (Galaxy Being)
3. import not working (Galaxy Being)
4. Re: import not working (Jesse Rudel)
5. Re: import not working (Galaxy Being)
----------------------------------------------------------------------
Message: 1
Date: Fri, 4 Jun 2021 17:58:51 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Data constraint?
Message-ID: <20210604155851.GA29481@extensa>
Content-Type: text/plain; charset=utf-8
Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto:
> If I have a type
>
> type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem
>
> and I want to have the values of CaHardness and Alkalinity constrained to
> positive Int and between certain high and low values, I could do a newtype to
> creater a NaturalChem number, thus never less than 0, but what is the best
> practice to insure these values are between a certain range? Types in
> Haskell can't go that far, can they? Reading this
Mhhh you could create a smart constructor
data Prova = ProvConst Int -- ProvConst does not get exported.
mkProva :: Int -> Prova -- This does get exported.
mkProva i | i > 100 = 100 -- or error "…
⁝
In a «Parse, don’t validate» [1] fashion.
If you need (as I suspect) to operate on those values, you will need
to define a few typeclasses (`numbers` [2] is a good example from
Hackage).
Would that do?
—F
[1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
[2]
https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html
------------------------------
Message: 2
Date: Fri, 4 Jun 2021 11:13:33 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Data constraint?
Message-ID:
<cafahfsxqtmunccgt6jypmxikowmxyaxmvpalty0ng5nz7-q...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Yes, I just discovered the HaskellWiki article on smart constructors! Will
give it a try.
On Fri, Jun 4, 2021, 11:01 AM Francesco Ariis <[email protected]> wrote:
> Il 03 giugno 2021 alle 17:40 Galaxy Being ha scritto:
> > If I have a type
> >
> > type WaterChem = CaHardness NaturalChem | Alkalinity NaturalChem
> >
> > and I want to have the values of CaHardness and Alkalinity constrained to
> > positive Int and between certain high and low values, I could do a
> newtype to
> > creater a NaturalChem number, thus never less than 0, but what is the
> best
> > practice to insure these values are between a certain range? Types in
> > Haskell can't go that far, can they? Reading this
>
> Mhhh you could create a smart constructor
>
> data Prova = ProvConst Int -- ProvConst does not get exported.
>
> mkProva :: Int -> Prova -- This does get exported.
> mkProva i | i > 100 = 100 -- or error "…
> ⁝
>
> In a «Parse, don’t validate» [1] fashion.
> If you need (as I suspect) to operate on those values, you will need
> to define a few typeclasses (`numbers` [2] is a good example from
> Hackage).
> Would that do?
> —F
>
> [1] https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/
> [2]
> https://hackage.haskell.org/package/numbers-3000.2.0.2/docs/Data-Number-Natural.html
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210604/21efd2fa/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 4 Jun 2021 16:48:11 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] import not working
Message-ID:
<cafahfsvreysp1ukj0d243kxom+shqsdhzwbfoos3q4h0cnk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I go to a directory. I run
stack install Safe
I start up ghci and get the Prelude prompt. I run
import Safe
and I get
import Safe
| ^^^^^^^^^^^
Failed, no modules loaded.
I'm once again frustrated. I try to load this hs file
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
import Safe
lookupDefault :: Eq a => a -> b -> [(a,b)] -> b
lookupDefault k _ (lookup k -> Just s) = s
lookupDefault _ d _ = d
headTup :: (a, [t]) -> [t]
headTup (headMay . snd -> Just n) = [n]
headTup _ = []
headNil :: [a] -> [a]
headNil (headMay -> Just x) = [x]
headNil _ = []
with the same result. What do I need to do?
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210604/54943e56/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 4 Jun 2021 22:18:27 +0000
From: Jesse Rudel <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] import not working
Message-ID:
<CADe=JVz7i6joVxQ=DijgNmmtr0tvc6_FoR=+srekqrms_sy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
How are you invoking ghci? If it's a stack project you can try stack ghci
if you haven't already.
On Fri, 4 Jun 2021 at 21:51, Galaxy Being <[email protected]> wrote:
> I go to a directory. I run
>
> stack install Safe
>
> I start up ghci and get the Prelude prompt. I run
>
> import Safe
>
> and I get
>
> import Safe
> | ^^^^^^^^^^^
> Failed, no modules loaded.
>
> I'm once again frustrated. I try to load this hs file
>
> {-# LANGUAGE ViewPatterns #-}
> {-# LANGUAGE NoMonomorphismRestriction #-}
>
> import Safe
>
> lookupDefault :: Eq a => a -> b -> [(a,b)] -> b
> lookupDefault k _ (lookup k -> Just s) = s
> lookupDefault _ d _ = d
>
> headTup :: (a, [t]) -> [t]
> headTup (headMay . snd -> Just n) = [n]
> headTup _ = []
>
> headNil :: [a] -> [a]
> headNil (headMay -> Just x) = [x]
> headNil _ = []
>
> with the same result. What do I need to do?
> --
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> [email protected]
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210604/8d9983e9/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 4 Jun 2021 22:47:57 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] import not working
Message-ID:
<CAFAhFSUnwSBdU=qDn=dyhnbivwtinsszonh6aojdptqbfla...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I run ghci with
> stack ghci
On Fri, Jun 4, 2021 at 5:19 PM Jesse Rudel <[email protected]> wrote:
> How are you invoking ghci? If it's a stack project you can try stack ghci
> if you haven't already.
>
> On Fri, 4 Jun 2021 at 21:51, Galaxy Being <[email protected]> wrote:
>
>> I go to a directory. I run
>>
>> stack install Safe
>>
>> I start up ghci and get the Prelude prompt. I run
>>
>> import Safe
>>
>> and I get
>>
>> import Safe
>> | ^^^^^^^^^^^
>> Failed, no modules loaded.
>>
>> I'm once again frustrated. I try to load this hs file
>>
>> {-# LANGUAGE ViewPatterns #-}
>> {-# LANGUAGE NoMonomorphismRestriction #-}
>>
>> import Safe
>>
>> lookupDefault :: Eq a => a -> b -> [(a,b)] -> b
>> lookupDefault k _ (lookup k -> Just s) = s
>> lookupDefault _ d _ = d
>>
>> headTup :: (a, [t]) -> [t]
>> headTup (headMay . snd -> Just n) = [n]
>> headTup _ = []
>>
>> headNil :: [a] -> [a]
>> headNil (headMay -> Just x) = [x]
>> headNil _ = []
>>
>> with the same result. What do I need to do?
>> --
>> ⨽
>> Lawrence Bottorff
>> Grand Marais, MN, USA
>> [email protected]
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210604/5a34d3c3/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 155, Issue 2
*****************************************