<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=""><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 class="Apple-tab-span" style="white-space:pre">        </span>&nbsp;&nbsp;<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: 0 0 0 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="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Gen&lt;InputKeyType, InputValueType, OutputKeyType, OutputValueType&gt;&nbsp;</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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">typealias</span><span style="font-variant-ligatures: no-common-ligatures" class=""> func1Type = (numberRecords:</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">InputKeyType</span><span style="font-variant-ligatures: no-common-ligatures" class="">, userRecord: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">InputValueType</span><span style="font-variant-ligatures: no-common-ligatures" class=""> ) -&gt; (</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OutputKeyType</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">OutputValueType</span><span style="font-variant-ligatures: no-common-ligatures" 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> afunc: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">( inFunc: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">func1Type</span><span style="font-variant-ligatures: no-common-ligatures" class=""> )&nbsp;</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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">afunc</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = inFunc</span></span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">&nbsp; &nbsp; }</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; 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="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> g: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Gen</span><span style="font-variant-ligatures: no-common-ligatures" class="">&lt;</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, (</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">), </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, (</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class="">)&gt; =</span></span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp; Gen</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">( inFunc:&nbsp;</span><span style="font-size: 12px;" class="">{&nbsp;</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">(numberRecords: </span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">, userRecord: (</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">, </span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">))&nbsp;</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">-&gt; (</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">, (</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">, </span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">)) </span><span style="font-size: 12px; font-variant-ligatures: no-common-ligatures; 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> b: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" 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 style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> (age, (numFriends, </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">))</span></span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}</span></div></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">&nbsp; &nbsp; )</span></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; 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-variant-ligatures: no-common-ligatures; 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: 0 0 0 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&lt;Int, (Int, Int), Int, (Int, Int)&gt; = {</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="">&nbsp; afunc = 0x00000001012024d0 $__lldb_expr7`partial apply forwarder for reabstraction thunk helper from @callee_owned (@unowned Swift.Int, @unowned Swift.Int, @unowned Swift.Int) -&gt; (@unowned (Swift.Int, (Swift.Int, Swift.Int))) to @callee_owned (@in Swift.Int, @in (Swift.Int, Swift.Int)) -&gt; (@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&lt;Swift.Int, (Swift.Int, Swift.Int), Swift.Int, (Swift.Int, Swift.Int)&gt;</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&lt;Int, (Int, Int), Int, (Int, Int)&gt;' 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="">&nbsp; &nbsp; &nbsp; &nbsp; ^ ~~~~~</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></body></html>