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. <$> and <*> pronunciation (Bob Ippolito)
2. Function Composition/Map (Animesh Saxena)
3. Re: Function Composition/Map (Animesh Saxena)
4. Re: Function Composition/Map (Thomas Bach)
5. Re: Using LTS et. al, a small thank you. (emacstheviking)
----------------------------------------------------------------------
Message: 1
Date: Thu, 5 Mar 2015 18:32:00 -0800
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] <$> and <*> pronunciation
Message-ID:
<CACwMPm959mtcd6S19nsuJ=r1j6cbdxvoka7e96rdje7t9zd...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Not a stupid question at all!
<$> is fmap (literally it is just an operator version of Functor's fmap)
<*> is ap (although ap may still be specialized to Monad rather than
Applicative, it is the same operation)
On Thu, Mar 5, 2015 at 5:39 PM, Max Schneider <[email protected]
<javascript:_e(%7B%7D,'cvml','[email protected]');>> wrote:
> (I really hope 'no stupid questions' holds here)
> I'm not even going to try framing this into a weighty or practical
> question; how do you pronounce the <$> and <*> Applicative functions?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> <javascript:_e(%7B%7D,'cvml','[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/20150305/a8a54774/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 06 Mar 2015 05:59:27 +0000 (GMT)
From: Animesh Saxena <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Function Composition/Map
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
I have a simple function?
fmove::Char->(Char,Char)->Char
? ? ?fmove s (x,y)
? ? ?| s == x = y
? ? ?| otherwise = s
If I say fmove 'a' ('a','b') it will move to 'b'
If I say fmove 'a' ('d','c') it will stay at 'a'
Now I am trying to use this for graph, coz one move can result in multiple
result nodes. For example in graphs you can have move from a to b and a to c.
So I was trying something like this,
:t (map fmove s) where s is the set of possible start nodes "abcd"
(map fmove s) :: [(Char, Char) -> Char]
Now I want to be able to pass the graph to this function and get all possible
list of endings. For example my graph can be
like?[('a','b'),('b','c'),('c','a'),('c','d'),('e','a')]. You can see that both
'a' and 'd' are possible from node 'c'.?
I can see that above type signature is wrong for passing the whole graph coz it
accepts?[(Char, Char) -> Char]. I initially started with foldl but problem is
recursion on top of foldl. The actual objective of the problem is to figure out
if a node is reachable from a start node or not. Hope the problem is clear, can
anyone suggest how to convert the map function to accept the graph??
For each of the possible start nodes (accumulating at each step) it should
apply it to the same graph.?
-Animesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150306/49f0d0dc/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 06 Mar 2015 06:33:00 +0000 (GMT)
From: Animesh Saxena <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Function Composition/Map
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
btw here's my ugly solution
type Node = Char
type Arc ?= (Node, Node)
solve [] arcs = []
solve (x:xs) arcs = (filter (/= ' ') $ map (fmove x) arcs) ++ (solve (filter
(/= ' ') $ map (fmove x) arcs) arcs)
fmove::Char->(Char,Char)->Char
fmove s (x,y)
? ? | s == x = y
? ? | otherwise = ' '
isGraph s e arcs = (length $ filter (==e) (take 20 ?$ solve [s] arcs)) > 0
This last check for isGraph should not use this evil number....."20"...coz of
infinite list...Hopefully should be able to figure it out..
-Animesh
On Mar 05, 2015, at 09:59 PM, Animesh Saxena <[email protected]> wrote:
I have a simple function?
fmove::Char->(Char,Char)->Char
? ? ?fmove s (x,y)
? ? ?| s == x = y
? ? ?| otherwise = s
If I say fmove 'a' ('a','b') it will move to 'b'
If I say fmove 'a' ('d','c') it will stay at 'a'
Now I am trying to use this for graph, coz one move can result in multiple
result nodes. For example in graphs you can have move from a to b and a to c.
So I was trying something like this,
:t (map fmove s) where s is the set of possible start nodes "abcd"
(map fmove s) :: [(Char, Char) -> Char]
Now I want to be able to pass the graph to this function and get all possible
list of endings. For example my graph can be
like?[('a','b'),('b','c'),('c','a'),('c','d'),('e','a')]. You can see that both
'a' and 'd' are possible from node 'c'.?
I can see that above type signature is wrong for passing the whole graph coz it
accepts?[(Char, Char) -> Char]. I initially started with foldl but problem is
recursion on top of foldl. The actual objective of the problem is to figure out
if a node is reachable from a start node or not. Hope the problem is clear, can
anyone suggest how to convert the map function to accept the graph??
For each of the possible start nodes (accumulating at each step) it should
apply it to the same graph.?
-Animesh
_______________________________________________
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/20150306/5027fc2c/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 6 Mar 2015 10:59:35 +0100
From: Thomas Bach <[email protected]>
To: Animesh Saxena <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Function Composition/Map
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Animesh Saxena <[email protected]> writes:
> I have a simple function
>
> fmove::Char->(Char,Char)->Char
> fmove s (x,y)
> | s == x = y
> | otherwise = s
>
> If I say fmove 'a' ('a','b') it will move to 'b'
> If I say fmove 'a' ('d','c') it will stay at 'a'
Note that `fmove 'a' ('c','a')` won't move you to 'c' and in general
`fmove x (y,z)` will move you to the node ' ' if x /= y. As for the
latter I'd suggest to use Maybe to have the possibility of a miss
encoded at type level:
import Data.Maybe
type Node = Char
type Edge = (Char,Char)
type Graph = [Edge]
fmove:: Node -> Edge -> Maybe Node
fmove s (x,y)
| s == x = Just y
| otherwise = Nothing
>
> Now I am trying to use this for graph, coz one move can result in
> multiple result nodes.
Using mapMaybe from Data.Maybe:
oneHopInGraph :: Graph -> Node -> [Node]
oneHopInGraph g n = mapMaybe (fmove n) g
> For example in graphs you can have move from a to b and a to c. So I
> was trying something like this,
>
> :t (map fmove s) where s is the set of possible start nodes "abcd"
>
> (map fmove s) :: [(Char, Char) -> Char]
Note that this is equivalent to `((map fmove) s)` ? function application
binds most in Haskell.
So if you want to map from several start nodes this would be
oneHopFromSeveral :: [Node] -> [Edge] -> [[Node]]
oneHopFromSeveral ns g = map (oneHopInGraph g) ns
> I can see that above type signature is wrong for passing the whole
> graph coz it accepts [(Char, Char) -> Char]. I initially started with
> foldl but problem is recursion on top of foldl.
My suggestion would be to take it easy in the beginning (I take it that
you are a beginner): try to write the recursions yourself and really try
to wrap your head around types. After writing the recursion by hand
start thinking about your code and its types really hard. From time to
time folds and maps will jump on you. And these Heureka moments will
happen more and more frequently.
> The actual objective of the problem is to figure out if a node is
> reachable from a start node or not. Hope the problem is clear, can
> anyone suggest how to convert the map function to accept the graph?
So lets see what we have here the type of the resulting function should
be
allPossibleHops :: Node -> Graph -> [Node]
right? So what is the condition when we can stop? When there aren't any
possible hops:
allPossibleHops n g
| oneHopInGraph g n == [] = []
in the other case the result are the next possible hops plus the result
of all possible hops of these hops:
| otherwise = nextHops ++ concatMap (flip allPossibleHops g) nextHops
where nextHops = oneHopInGraph g n
Testing:
?> allPossibleHops 'a' [('a','b'),('b','c'),('c','d'),('e','a')]
"bcd"
You have to make sure that there aren't any cycles for this solution to
work!
I hope this helps.
Regards
Thomas.
------------------------------
Message: 5
Date: Fri, 6 Mar 2015 11:16:39 +0000
From: emacstheviking <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using LTS et. al, a small thank you.
Message-ID:
<caeieuujbglqt+9kkp6qewpgp70ix9pvr8fgs1sxmedosc2m...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
:)
You have a point. I have been on some really uncomfortable lists over the
years!!
I like the precision of the answers. Haskell hurts your head. (But in a
good way). That's a T-shirt slogan right there!
Sean.
On 5 March 2015 at 18:30, Dimitri DeFigueiredo <[email protected]>
wrote:
> This is the friendliest mailing list I have ever subscribed to.
>
> The people in this list are so nice that even if Haskell were not so
> wonderfully elegant, I would like to learn it just to be able to chat and
> work with them.
>
> :-)
>
> Dimitri
>
>
>
> On 05/03/15 12:22, emacstheviking wrote:
>
> First, find yourself a Pharrel Williams youtube video of Happy!
>
> ;)
>
> It might seem crazy what I'm about to say
> Functional is here, you can take a break
> No more OO confusion that takes up too much space
> Punch the air like you don't care it's cool as I say...
>
> Because I code Haskell
> Code along if you feel like a project without a boss
> Because I code Haskell
> Code along if you know that OO is just a bunch of dross
> Because I code Haskell
> Code along if you know what productivity is to you
> Because I code Haskell
> Clap along if you that's what you wanna do
>
> I am sure I could write more but that floated in out of nowhere and
> stuck as the song came on the radio!! LMAO
>
>
> In all honesty, I have now got OpenGL, http-client and a bunch of stuff
> all playing nicely. Thanks very much everybody for your help yesterday,
> it's noce to be hacking Haskell once more.
>
> I'm happy..........
>
>
>
>
> _______________________________________________
> Beginners mailing
> [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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150306/152dc3ac/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 26
*****************************************