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. Why can't I return a partially applied function in my
example? (Umair Saeed)
2. Re: Why can't I return a partially applied function in my
example? (Andres Loeh)
3. Re: Why can't I return a partially applied function in my
example? (Tony Morris)
4. Re: Why can't I return a partially applied function in my
example? (Francesco Ariis)
5. Can't cast an IO String to s Astring (chanti houda)
----------------------------------------------------------------------
Message: 1
Date: Fri, 23 Oct 2015 05:42:35 -0700
From: Umair Saeed <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Why can't I return a partially applied
function in my example?
Message-ID:
<cad2rvxdgjlllgery5koyhnjpwngopljfk34mbawmwob_x7d...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hello all,
I'm learning Haskell, and started to go through a set of intermediate
exercises (
https://www.fpcomplete.com/user/DanBurton/20-intermediate-exercises). I am
a bit puzzled about one of the exercises, and hope someone can help me
understand why one of my solutions doesn't work.
We have a typeclass, Misty (only the relevant banana function shown) as:
class Misty m where
banana :: (a -> m b) -> m a -> m b
The exercise asks to implement this typeclass for the type ?((->) t)?. I
started off by filling in the relevant types, and I get:
banana :: (a -> ((->) t b) ) -> ((->) t a) -> ((->) t b)
banana :: (a -> (t -> b)) -> (t -> a) -> (t -> b)
Based on this, I decided to implement banana as:
banana f g = (\x -> f (g x))
Here is my thought process:
- The type of f is ?(a -> t -> b)?, and the type of g is ?(t -> a)?
- g converts an argument of type ?t? into a result of type ?a?.
- I then pass the result of ?(g x)? (which is of type ?a?) as an argument
to ?f?.
- At this point, ?f? would be partially applied, and I *expect* to get a
result of type ?(t -> b)?
However, when I try to build my solution, I get the following error (code
is in a file called intermediate-help.hs):
[1 of 1] Compiling Main ( intermediate-help.hs, interpreted )
intermediate-help.hs:7:25:
Couldn't match expected type ?b? with actual type ?t -> b?
?b? is a rigid type variable bound by
the type signature for
banana :: (a -> t -> b) -> (t -> a) -> t -> b
at intermediate-help.hs:7:5
Relevant bindings include
x :: t (bound at intermediate-help.hs:7:20)
g :: t -> a (bound at intermediate-help.hs:7:14)
f :: a -> t -> b (bound at intermediate-help.hs:7:12)
banana :: (a -> t -> b) -> (t -> a) -> t -> b
(bound at intermediate-help.hs:7:5)
In the expression: f (g x)
In the expression: (\ x -> f (g x))
Failed, modules loaded: none.
So here's my confusion: The compiler is complaining that it cannot match
expected type ?b? with actual type ?t -> b?. However, as I reasoned above,
when I wrote this code, I expected to get type ?t -> b?. Clearly, my
thought process has a hole, and I need help/advice from more experienced
Haskellers to identify what I am missing.
Thank you for any help,
~Umair
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151023/ae22b250/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 23 Oct 2015 14:49:10 +0200
From: Andres Loeh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Why can't I return a partially
applied function in my example?
Message-ID:
<CALjd_v6BsQZjL60hQXrZJFzuONJLbRLaPGbq_Qi7=4ftkpf...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hi.
You are right, that 'f (g x)' has type '(t -> b)'. However, you're not
returning 'f (g x)'. You're returning '\x -> f (g x)', and that has
type 't -> (t -> b)', because 'x' is of type 't'. So you're returning
a 't -> (t -> b)' where a 't -> b' is expected. Since the 't -> ...'
of both types matches, GHC complains only about the mismatch of the
result types.
Cheers,
Andres
On Fri, Oct 23, 2015 at 2:42 PM, Umair Saeed <[email protected]> wrote:
> Hello all,
> I'm learning Haskell, and started to go through a set of intermediate
> exercises
> (https://www.fpcomplete.com/user/DanBurton/20-intermediate-exercises). I am
> a bit puzzled about one of the exercises, and hope someone can help me
> understand why one of my solutions doesn't work.
>
> We have a typeclass, Misty (only the relevant banana function shown) as:
>
>
> class Misty m where
> banana :: (a -> m b) -> m a -> m b
>
>
> The exercise asks to implement this typeclass for the type ?((->) t)?. I
> started off by filling in the relevant types, and I get:
>
> banana :: (a -> ((->) t b) ) -> ((->) t a) -> ((->) t b)
> banana :: (a -> (t -> b)) -> (t -> a) -> (t -> b)
>
> Based on this, I decided to implement banana as:
>
> banana f g = (\x -> f (g x))
>
> Here is my thought process:
> - The type of f is ?(a -> t -> b)?, and the type of g is ?(t -> a)?
> - g converts an argument of type ?t? into a result of type ?a?.
> - I then pass the result of ?(g x)? (which is of type ?a?) as an argument to
> ?f?.
> - At this point, ?f? would be partially applied, and I *expect* to get a
> result of type ?(t -> b)?
>
>
> However, when I try to build my solution, I get the following error (code is
> in a file called intermediate-help.hs):
>
> [1 of 1] Compiling Main ( intermediate-help.hs, interpreted )
>
> intermediate-help.hs:7:25:
> Couldn't match expected type ?b? with actual type ?t -> b?
> ?b? is a rigid type variable bound by
> the type signature for
> banana :: (a -> t -> b) -> (t -> a) -> t -> b
> at intermediate-help.hs:7:5
> Relevant bindings include
> x :: t (bound at intermediate-help.hs:7:20)
> g :: t -> a (bound at intermediate-help.hs:7:14)
> f :: a -> t -> b (bound at intermediate-help.hs:7:12)
> banana :: (a -> t -> b) -> (t -> a) -> t -> b
> (bound at intermediate-help.hs:7:5)
> In the expression: f (g x)
> In the expression: (\ x -> f (g x))
> Failed, modules loaded: none.
>
>
>
> So here's my confusion: The compiler is complaining that it cannot match
> expected type ?b? with actual type ?t -> b?. However, as I reasoned above,
> when I wrote this code, I expected to get type ?t -> b?. Clearly, my thought
> process has a hole, and I need help/advice from more experienced Haskellers
> to identify what I am missing.
>
> Thank you for any help,
> ~Umair
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
------------------------------
Message: 3
Date: Fri, 23 Oct 2015 23:02:50 +1000
From: Tony Morris <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Why can't I return a partially
applied function in my example?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252
FYI, the material you are using was stolen. Here is the original.
http://blog.tmorris.net/posts/20-intermediate-haskell-exercises/
On 23/10/15 22:42, Umair Saeed wrote:
> Hello all,
> I'm learning Haskell, and started to go through a set of intermediate
> exercises
> (https://www.fpcomplete.com/user/DanBurton/20-intermediate-exercises). I
> am a bit puzzled about one of the exercises, and hope someone can help
> me understand why one of my solutions doesn't work.
>
> We have a typeclass, Misty (only the relevant banana function shown) as:
>
>
> class Misty m where
> banana :: (a -> m b) -> m a -> m b
>
>
> The exercise asks to implement this typeclass for the type ?((->) t)?. I
> started off by filling in the relevant types, and I get:
>
> banana :: (a -> ((->) t b) ) -> ((->) t a) -> ((->) t b)
> banana :: (a -> (t -> b)) -> (t -> a) -> (t -> b)
>
> Based on this, I decided to implement banana as:
>
> banana f g = (\x -> f (g x))
>
> Here is my thought process:
> - The type of f is ?(a -> t -> b)?, and the type of g is ?(t -> a)?
> - g converts an argument of type ?t? into a result of type ?a?.
> - I then pass the result of ?(g x)? (which is of type ?a?) as an
> argument to ?f?.
> - At this point, ?f? would be partially applied, and I *expect* to get a
> result of type ?(t -> b)?
>
>
> However, when I try to build my solution, I get the following error
> (code is in a file called intermediate-help.hs):
>
> [1 of 1] Compiling Main ( intermediate-help.hs, interpreted )
>
> intermediate-help.hs:7:25:
> Couldn't match expected type ?b? with actual type ?t -> b?
> ?b? is a rigid type variable bound by
> the type signature for
> banana :: (a -> t -> b) -> (t -> a) -> t -> b
> at intermediate-help.hs:7:5
> Relevant bindings include
> x :: t (bound at intermediate-help.hs:7:20)
> g :: t -> a (bound at intermediate-help.hs:7:14)
> f :: a -> t -> b (bound at intermediate-help.hs:7:12)
> banana :: (a -> t -> b) -> (t -> a) -> t -> b
> (bound at intermediate-help.hs:7:5)
> In the expression: f (g x)
> In the expression: (\ x -> f (g x))
> Failed, modules loaded: none.
>
>
>
> So here's my confusion: The compiler is complaining that it cannot match
> expected type ?b? with actual type ?t -> b?. However, as I reasoned
> above, when I wrote this code, I expected to get type ?t -> b?. Clearly,
> my thought process has a hole, and I need help/advice from more
> experienced Haskellers to identify what I am missing.
>
> Thank you for any help,
> ~Umair
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Fri, 23 Oct 2015 15:32:09 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Why can't I return a partially
applied function in my example?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Oct 23, 2015 at 11:02:50PM +1000, Tony Morris wrote:
> FYI, the material you are using was stolen. Here is the original.
>
> http://blog.tmorris.net/posts/20-intermediate-haskell-exercises/
:| No attribution/link whatsoever on the article page, (on the
author's page [1] you can read "Shamelessly stolen from <url>").
Can you confirm noone asked you permission to Ctrl-c/v your post?
I am pretty sure FP Complete is several notches better than
BuzzFeed and would act upon it.
[1] https://www.fpcomplete.com/user/DanBurton
------------------------------
Message: 5
Date: Fri, 23 Oct 2015 15:32:50 +0000 (UTC)
From: chanti houda <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Can't cast an IO String to s Astring
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hello, I'm writing a Haskell code which consists to read a text file, parse it
and thansform the parsing result on a specific language.I have a function
affiche which takes a data type Ctrl and returns a String. This is the
transformation funtion.I have also anothe function parsctrl, which parse the
contents of a text file ("ctrl.txt") and after looks for a specific value
("A01") in the parse result (function cherchectrl).
I need to use the result of the parsectrl function in another function fc.?
The code is composed of three functions
parsectrl = do
?f <- readFile "ctrl.txt"
?let Right r = parse? parseCtrl? " " f?let rez =cherchectrl ( r) "A01"
?return (rez)
fc[]? =[]
fc((door,[(all,v1),(alt,v2),(lint,v3),(w,v4),(r,v5),(loc,v6),(
etat,v7),(ruin,v8)]):ls ) = ("&OUV ID='"++door ++"', ALLEGE="++show((moi
v1)/1000)++", LINTEAU="++show((moi v3)/1000)++", LARGEUR="++show((moi
v4)/1000)++", COEF=0.7, ALT="++show((moi v2)/1000)++", LOCIDS='"++v6++"',
CTRLID='"++ v7++"', CTRLID_RUIN='"++ v8++" /" ++"\n" ++"&CTRL ID='"++v7++"', "
++ "ON_INI=.FALSE., DURATION=0 / \n"++"&CTRL ID='"++v8++"', LOCID='"++?
((parses("'"++v6++"'"))!!0) ++affiche(parsectrl)++ " / \n\n"? )++fc(ls)
The parsectrl returns an IO String, but the function affiche needs a String as
input and even when I tried to adapt the affiche function to take an? IO String
-> String I can't.the result of fc must be a String too.
The IO String comes from the parsectrl function.
Can you help me to solve this problem: how can I transform an IO String to a
String.
Thank you by advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20151023/be951e9e/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 88, Issue 20
*****************************************