<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thank you Saagar for looking over this code for me. I guess I got really caught up in the weird diagnostic message and assumed things weren’t working.<div class="">Now I see that ‘afunc’ works as I expected:</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" style="font-size: 12px;" class="">60> g.afunc(numberRecords:1,userRecord:(13,9))</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class="">13 9</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class="">$R3: (Int, (Int, Int)) = {</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class=""> 0 = 13</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class=""> 1 = {</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class=""> 0 = 9</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class=""> 1 = 1</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class=""> }</font></div><div class=""><font face="Menlo" style="font-size: 12px;" class="">}</font></div></div><div class=""><br class=""></div><div class="">Although I would be interested in why the compiler spits out the first message in the first place (e.g. the message with the strange description of afunc).</div><div class=""><br class=""></div><div class="">Looking forward to see what I can do with Swift,</div><div class=""><br class=""></div><div class="">Doug Hill</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 15, 2016, at 6:49 PM, Saagar Jha <<a href="mailto:saagarjha28@gmail.com" class="">saagarjha28@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">`Gen` defines `afunc`, but you’re trying to access `aFunc`.<br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Jun 15, 2016 at 6:22 PM Doug Hill via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">I’m just starting to learn Swift and attempting to do some functional-style programming. Specifically I’m learning how to create generic algorithms that can be reused for many different types.</div><div class="">What I’m attempting to do is create a new object, passing functions to the initializer. The class would store these functions as properties and then use them for functional-style algorithms.<div class=""><br class=""></div><div class="">The problem is I’m running into weird compiler errors/messages that I’m trying to figure out. I'm hoping someone here can give me some pointers on what these errors mean, and most likely what I’m doing wrong.</div><div class=""><br class=""></div></div><div class=""><span style="white-space:pre-wrap" class="">        </span> <font face="Menlo" style="font-size:12px" class="">Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31) Target: x86_64-apple-macosx10.9</font></div><div class=""><font face="Menlo" style="font-size:12px" class=""><br class=""></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><div class=""><font face="Menlo" style="font-size:12px" class="">// =====================================================================</font></div></div><div class=""><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span style="color:rgb(187,44,162)" class="">class</span><span class=""> Gen<InputKeyType, InputValueType, OutputKeyType, OutputValueType> </span></span><span style="font-size:12px" class="">{</span></div></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">typealias</span><span class=""> func1Type = (numberRecords:</span><span style="color:rgb(79,129,135)" class="">InputKeyType</span><span class="">, userRecord: </span><span style="color:rgb(79,129,135)" class="">InputValueType</span><span class=""> ) -> (</span><span style="color:rgb(79,129,135)" class="">OutputKeyType</span><span class="">, </span><span style="color:rgb(79,129,135)" class="">OutputValueType</span><span class="">)</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px" class=""><span style="font-size:12px" class=""><br class=""></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">var</span><span class=""> afunc: </span><span style="color:rgb(79,129,135)" class="">func1Type</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px" class=""><span style="font-size:12px" class=""><br class=""></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">init</span><span class="">( inFunc: </span><span style="color:rgb(79,129,135)" class="">func1Type</span><span class=""> ) </span></span><span style="font-size:12px" class="">{</span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(79,129,135)" class="">afunc</span><span class=""> = inFunc</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""> }</span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class="">}</span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px" class=""><span style="font-size:12px" class=""><br class=""></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span style="color:rgb(187,44,162)" class="">var</span><span class=""> g: </span><span style="color:rgb(79,129,135)" class="">Gen</span><span class=""><</span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">, (</span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">, </span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">), </span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">, (</span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">, </span><span style="color:rgb(112,61,170)" class="">Int</span><span class="">)> =</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""> Gen</span><span style="font-size:12px" class="">( inFunc: </span><span style="font-size:12px" class="">{ </span><span style="font-size:12px" class="">(numberRecords: </span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">, userRecord: (</span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">, </span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">)) </span><span style="font-size:12px" class="">-> (</span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">, (</span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">, </span><span style="font-size:12px;color:rgb(112,61,170)" class="">Int</span><span style="font-size:12px" class="">)) </span><span style="font-size:12px;color:rgb(187,44,162)" class="">in</span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">var</span><span class=""> b: </span><span style="color:rgb(112,61,170)" class="">Int</span><span class=""> = numberRecords</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">var</span><span class=""> (age, numFriends) = userRecord</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(61,29,129)" class="">print</span><span class="">( (age), (numFriends) )</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><span class=""> </span><span style="color:rgb(187,44,162)" class="">return</span><span class=""> (age, (numFriends, </span><span style="color:rgb(39,42,216)" class="">1</span><span class="">))</span></span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""> }</span></div></div><div class=""><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""> )</span></div></div><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><div style="font-family:Helvetica;font-size:14px" class="">// =====================================================================</div></span></div></blockquote><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><div style="font-family:Helvetica;font-size:14px" class=""></div></span></div><div style="margin:0px;line-height:normal" class=""><font face="HelveticaNeue" class=""><br class=""></font></div><div style="margin:0px;line-height:normal" class=""><font face="HelveticaNeue" class="">What I get as output from the Swift compiler are these confusing messages. I included some print statements that hopefully gives some more info about what’s happening.</font></div><div style="margin:0px;line-height:normal;font-family:Menlo" class=""><span style="font-size:12px" class=""><br class=""></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">g: Gen<Int, (Int, Int), Int, (Int, Int)> = {</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class=""> afunc = 0x00000001012024d0 $__lldb_expr7`partial apply forwarder for reabstraction thunk helper from @callee_owned (@unowned Swift.Int, @unowned Swift.Int, @unowned Swift.Int) -> (@unowned (Swift.Int, (Swift.Int, Swift.Int))) to @callee_owned (@in Swift.Int, @in (Swift.Int, Swift.Int)) -> (@out (Swift.Int, (Swift.Int, Swift.Int))) at repl6.swift</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">}</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class=""><br class=""></span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">print( (g) )</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">Gen<Swift.Int, (Swift.Int, Swift.Int), Swift.Int, (Swift.Int, Swift.Int)></span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class=""><br class=""></span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">print( (g.aFunc) )</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><font face="Menlo" class=""><span style="font-size:12px" class="">repl.swift:48:9: error: value of type 'Gen<Int, (Int, Int), Int, (Int, Int)>' has no member 'aFunc'</span></font></div></div><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><span style="font-size:12px;font-family:Menlo" class=""> ^ ~~~~~</span></div></div></blockquote><div style="margin:0px;line-height:normal" class=""><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">There’s a good chance I’m doing something wrong but I don’t know how to figure out what that problem is. Any ideas?</div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">Thanks.</div><div style="margin:0px;line-height:normal" class=""><br class=""></div><div style="margin:0px;line-height:normal" class="">Doug</div></div></div>_______________________________________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class="">
</blockquote></div></div><div dir="ltr" class="">-- <br class=""></div><div data-smartmail="gmail_signature" class=""><div dir="ltr" class="">-Saagar Jha</div></div>
</div></blockquote></div><br class=""></div></body></html>