<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> <font face="Menlo" class="" style="font-size: 12px;">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" class="" style="font-size: 12px;"><br class=""></font></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><div class=""><font face="Menlo" class="" style="font-size: 12px;">// =====================================================================</font></div></div><div class=""><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">class</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> Gen<InputKeyType, InputValueType, OutputKeyType, OutputValueType> </span></span><span class="" style="font-size: 12px;">{</span></div></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">typealias</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> func1Type = (numberRecords:</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">InputKeyType</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, userRecord: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">InputValueType</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> ) -> (</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">OutputKeyType</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">OutputValueType</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;"><span class="" style="font-size: 12px;"><br class=""></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> afunc: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">func1Type</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;"><span class="" style="font-size: 12px;"><br class=""></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">init</span><span class="" style="font-variant-ligatures: no-common-ligatures;">( inFunc: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">func1Type</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> ) </span></span><span class="" style="font-size: 12px;">{</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">afunc</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = inFunc</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> }</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;">}</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;"><span class="" style="font-size: 12px;"><br class=""></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> g: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">Gen</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, (</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">), </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, (</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)> =</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;"> Gen</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">( inFunc: </span><span class="" style="font-size: 12px;">{ </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">(numberRecords: </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">, userRecord: (</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">)) </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">-> (</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">, (</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures;">)) </span><span class="" style="font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">in</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> b: </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);">Int</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = numberRecords</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> (age, numFriends) = userRecord</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);">print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">( (age), (numFriends) )</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">return</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> (age, (numFriends, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);">1</span><span class="" style="font-variant-ligatures: no-common-ligatures;">))</span></span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> }</span></div></div><div class=""><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"> )</span></div></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><div class="" style="font-family: Helvetica; font-size: 14px;">// =====================================================================</div></span></div></blockquote><div class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 12px;"><div class="" style="font-family: Helvetica; font-size: 14px;"></div></span></div><div class="" style="margin: 0px; line-height: normal;"><font face="HelveticaNeue" class=""><br class=""></font></div><div class="" style="margin: 0px; line-height: normal;"><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 class="" style="margin: 0px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 12px;"><br class=""></span></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">g: Gen<Int, (Int, Int), Int, (Int, Int)> = {</span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;"> 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 class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">}</span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;"><br class=""></span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">print( (g) )</span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">Gen<Swift.Int, (Swift.Int, Swift.Int), Swift.Int, (Swift.Int, Swift.Int)></span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;"><br class=""></span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">print( (g.aFunc) )</span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><font face="Menlo" class=""><span class="" style="font-size: 12px;">repl.swift:48:9: error: value of type 'Gen<Int, (Int, Int), Int, (Int, Int)>' has no member 'aFunc'</span></font></div></div><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-size: 12px; font-family: Menlo;"> ^ ~~~~~</span></div></div></blockquote><div class="" style="margin: 0px; line-height: normal;"><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">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 class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">Thanks.</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;">Doug</div></div></body></html>