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. case statement and guarded equations (PATRICK BROWNE)
2. Re: case statement and guarded equations (Rein Henrichs)
3. Re: case statement and guarded equations (Rein Henrichs)
4. Re: case statement and guarded equations (Rein Henrichs)
5. using Shake to compile c++ (Roger Mason)
----------------------------------------------------------------------
Message: 1
Date: Fri, 7 Jul 2017 23:23:25 +0100
From: PATRICK BROWNE <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] case statement and guarded equations
Message-ID:
<CAGFLrKc=i0oukpmnofjzfwf919kkj-s6_qrnhtchyhh1emc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
In the case statement for the half function I think variable m is bound to
the value of (snd (half (n - 1)). With this assumption, I have have
written a guarded version called half1. Is it always possible to write case
statements as a set of conditional equations? My intuition is that this
should be possible and that the guarded version reduces pattern matching?
Thanks,
Pat
data EvenOdd = Even | Odd deriving (Show,Eq)
half 0 = (Even,0)
half n = case half (n-1) of (Even,m) -> (Odd,m)
(Odd,m) -> (Even,m+1)
half1 0 = (Even , 0)
half1 n | (fst (half (n - 1)) == Even) = (Odd , (snd (half (n - 1))))
half1 n | (fst (half (n - 1)) == Odd) = (Even , ((snd (half (n - 1)))
+ 1))
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
ríomhphost nó sna hiatáin seo. www.dit.ie
Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170707/51dbc4da/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 07 Jul 2017 22:38:06 +0000
From: Rein Henrichs <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] case statement and guarded equations
Message-ID:
<cajp6g8wqfidfwzr4bfyvgkomtjurr2_8isvmbzechjx7y1i...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Quoting the report[1], "A boolean guard, g, is semantically equivalent to
the pattern guard True <- g," which means the answer is "Yes". A boolean
guard is equivalent to a pattern match. A predicate involving ==, however,
introduces an Eq constraint that would not be required by pattern matching.
For a properly equivalent guard, you need to write your predicates using
pattern matching
isEven Even = True
isEven _ = False
to avoid the spurious Eq constraint.
[1]
https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170707/b1fc864f/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 07 Jul 2017 22:40:20 +0000
From: Rein Henrichs <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] case statement and guarded equations
Message-ID:
<cajp6g8yqenw7mqfbhqfxmb71mvpzdzzywoxe+in-ovmwo74...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'll also mention that GHC's exhaustiveness checker will mark the pattern
match as exhaustive (since EvenOdd must be either Even or Odd and both
cases are given) but warn about the two guards since it doesn't know that
they form a dichotomy. You can use `otherwise`, which is just another name
for True, to convince GHC that your guards are exhaustive.
On Fri, Jul 7, 2017 at 3:38 PM Rein Henrichs <[email protected]>
wrote:
> Quoting the report[1], "A boolean guard, g, is semantically equivalent to
> the pattern guard True <- g," which means the answer is "Yes". A boolean
> guard is equivalent to a pattern match. A predicate involving ==, however,
> introduces an Eq constraint that would not be required by pattern matching.
> For a properly equivalent guard, you need to write your predicates using
> pattern matching
>
> isEven Even = True
> isEven _ = False
>
> to avoid the spurious Eq constraint.
>
> [1]
> https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170707/9e939823/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 07 Jul 2017 22:42:10 +0000
From: Rein Henrichs <[email protected]>
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Subject: Re: [Haskell-beginners] case statement and guarded equations
Message-ID:
<cajp6g8xtj-1v1htfnt_kv-0kjwkoq5zo4cco6fsh2cwvgga...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Sorry for the multiple responses. I just wanted to mention that the
equivalent guards do not "reduce pattern matching", they just move it
around a bit. Pattern matching is fundamental and pretty much everything
involved in evaluation desugars to pattern matching eventually.
On Fri, Jul 7, 2017 at 3:40 PM Rein Henrichs <[email protected]>
wrote:
> I'll also mention that GHC's exhaustiveness checker will mark the pattern
> match as exhaustive (since EvenOdd must be either Even or Odd and both
> cases are given) but warn about the two guards since it doesn't know that
> they form a dichotomy. You can use `otherwise`, which is just another name
> for True, to convince GHC that your guards are exhaustive.
>
> On Fri, Jul 7, 2017 at 3:38 PM Rein Henrichs <[email protected]>
> wrote:
>
>> Quoting the report[1], "A boolean guard, g, is semantically equivalent to
>> the pattern guard True <- g," which means the answer is "Yes". A boolean
>> guard is equivalent to a pattern match. A predicate involving ==, however,
>> introduces an Eq constraint that would not be required by pattern matching.
>> For a properly equivalent guard, you need to write your predicates using
>> pattern matching
>>
>> isEven Even = True
>> isEven _ = False
>>
>> to avoid the spurious Eq constraint.
>>
>> [1]
>> https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-460003.13
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20170707/b4106325/attachment-0001.html>
------------------------------
Message: 5
Date: Sat, 08 Jul 2017 08:49:39 -0230
From: Roger Mason <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] using Shake to compile c++
Message-ID: <[email protected]>
Content-Type: text/plain
Hello,
I am trying the Shake build system to compile some c++. I would
appreciate some advice on how to use the result of a call to pkg-config
in constructing a compiler command. This is what I have currently in Build.hs:
import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="bin"} $ do
want ["bin/makelist", "bin/makejpeg" <.> exe]
phony "clean" $ do
putNormal "Cleaning files in _build"
removeFilesAfter "bin" ["//*"]
"bin/makelist" <.> exe %> \out -> do
cs <- getDirectoryFiles "" ["src/MakeList.cxx"]
let os = ["objects" </> c -<.> "o" | c <- cs]
need os
cmd "c++ -o" [out] os
"bin/makejpeg" <.> exe %> \out -> do
cs <- getDirectoryFiles "" ["src/MakeJpeg.cxx"]
let os = ["objects" </> c -<.> "o" | c <- cs]
need os
cmd "c++ -o" [out] os
"objects//*.o" %> \out -> do
let c = dropDirectory1 $ out -<.> "cxx"
let m = out -<.> "m"
let i = cmd "pkg-config glib-2.0 --cflags"
() <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i]
needMakefileDependencies m
This is the output from 'stack runhaskell Build.sh':
Build.hs:29:17: error:
* Ambiguous type variable `t0' arising from a use of `cmd'
prevents the constraint `(CmdArguments t0)' from being solved.
Relevant bindings include i :: t0 (bound at Build.hs:29:13)
Probable fix: use a type annotation to specify what `t0' should be.
These potential instances exist:
instance CmdResult r => CmdArguments (IO r)
-- Defined in `Development.Shake.Command'
instance CmdResult r => CmdArguments (Action r)
-- Defined in `Development.Shake.Command'
instance (Development.Shake.Command.Arg a, CmdArguments r) =>
CmdArguments (a -> r)
-- Defined in `Development.Shake.Command'
...plus one other
(use -fprint-potential-instances to see them all)
* In the expression: cmd "pkg-config glib-2.0 --cflags"
In an equation for `i': i = cmd "pkg-config glib-2.0 --cflags"
In the expression:
do { let c = dropDirectory1 $ out -<.> "cxx";
let m = out -<.> "m";
let i = cmd "pkg-config glib-2.0 --cflags";
() <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i];
.... }
Build.hs:30:15: error:
* Ambiguous type variable `t0' arising from a use of `cmd'
prevents the constraint `(Development.Shake.Command.Arg
[t0])' from being solved.
Relevant bindings include i :: t0 (bound at Build.hs:29:13)
Probable fix: use a type annotation to specify what `t0' should be.
These potential instances exist:
instance Development.Shake.Command.Arg [CmdOption]
-- Defined in `Development.Shake.Command'
instance Development.Shake.Command.Arg [String]
-- Defined in `Development.Shake.Command'
instance Development.Shake.Command.Arg String
-- Defined in `Development.Shake.Command'
* In a stmt of a 'do' block:
() <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i]
In the expression:
do { let c = dropDirectory1 $ out -<.> "cxx";
let m = out -<.> "m";
let i = cmd "pkg-config glib-2.0 --cflags";
() <- cmd "c++ -c" [c] "-o" [out] "-MMD -MF" [m] [i];
.... }
In the second argument of `(%>)', namely
`\ out
-> do { let ...;
let ...;
.... }'
I would appreciate any help in getting the output of the call to
pkg-config into the compiler invocation.
Thanks,
Roger
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 109, Issue 10
******************************************