[Haskell-beginners] Function Composition/Map
Animesh Saxena
animeshsaxena at icloud.com
Fri Mar 6 05:59:27 UTC 2015
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.html>
More information about the Beginners
mailing list