<div dir="ltr">`Gen` defines `afunc`, but you’re trying to access `aFunc`.<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 15, 2016 at 6:22 PM Doug Hill via swift-users &lt;<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>&gt; wrote:<br></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"><div>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>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><br></div><div>The problem is I’m running into weird compiler errors/messages that I’m trying to figure out. I&#39;m hoping someone here can give me some pointers on what these errors mean, and most likely what I’m doing wrong.</div><div><br></div></div><div><span style="white-space:pre-wrap">        </span>  <font face="Menlo" 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><font face="Menlo" style="font-size:12px"><br></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="Menlo" style="font-size:12px">// =====================================================================</font></div></div><div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span style="color:rgb(187,44,162)">class</span><span> Gen&lt;InputKeyType, InputValueType, OutputKeyType, OutputValueType&gt; </span></span><span style="font-size:12px">{</span></div></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>    </span><span style="color:rgb(187,44,162)">typealias</span><span> func1Type = (numberRecords:</span><span style="color:rgb(79,129,135)">InputKeyType</span><span>, userRecord: </span><span style="color:rgb(79,129,135)">InputValueType</span><span> ) -&gt; (</span><span style="color:rgb(79,129,135)">OutputKeyType</span><span>, </span><span style="color:rgb(79,129,135)">OutputValueType</span><span>)</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>    </span><span style="color:rgb(187,44,162)">var</span><span> afunc: </span><span style="color:rgb(79,129,135)">func1Type</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>    </span><span style="color:rgb(187,44,162)">init</span><span>( inFunc: </span><span style="color:rgb(79,129,135)">func1Type</span><span> ) </span></span><span style="font-size:12px">{</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>        </span><span style="color:rgb(79,129,135)">afunc</span><span> = inFunc</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">    }</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">}</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo;min-height:21px"><span style="font-size:12px"><br></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span style="color:rgb(187,44,162)">var</span><span> g: </span><span style="color:rgb(79,129,135)">Gen</span><span>&lt;</span><span style="color:rgb(112,61,170)">Int</span><span>, (</span><span style="color:rgb(112,61,170)">Int</span><span>, </span><span style="color:rgb(112,61,170)">Int</span><span>), </span><span style="color:rgb(112,61,170)">Int</span><span>, (</span><span style="color:rgb(112,61,170)">Int</span><span>, </span><span style="color:rgb(112,61,170)">Int</span><span>)&gt; =</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">    Gen</span><span style="font-size:12px">( inFunc: </span><span style="font-size:12px">{ </span><span style="font-size:12px">(numberRecords: </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, userRecord: (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">)) </span><span style="font-size:12px">-&gt; (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, (</span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">, </span><span style="font-size:12px;color:rgb(112,61,170)">Int</span><span style="font-size:12px">)) </span><span style="font-size:12px;color:rgb(187,44,162)">in</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>                </span><span style="color:rgb(187,44,162)">var</span><span> b: </span><span style="color:rgb(112,61,170)">Int</span><span> = numberRecords</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>                </span><span style="color:rgb(187,44,162)">var</span><span> (age, numFriends) = userRecord</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>                </span><span style="color:rgb(61,29,129)">print</span><span>( (age), (numFriends) )</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><span>                </span><span style="color:rgb(187,44,162)">return</span><span> (age, (numFriends, </span><span style="color:rgb(39,42,216)">1</span><span>))</span></span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">            }</span></div></div><div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px">    )</span></div></div><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><div style="font-family:Helvetica;font-size:14px">// =====================================================================</div></span></div></blockquote><div style="margin:0px;line-height:normal;font-family:Menlo"><span style="font-size:12px"><div style="font-family:Helvetica;font-size:14px"></div></span></div><div style="margin:0px;line-height:normal"><font face="HelveticaNeue"><br></font></div><div style="margin:0px;line-height:normal"><font face="HelveticaNeue">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"><span style="font-size:12px"><br></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">g: Gen&lt;Int, (Int, Int), Int, (Int, Int)&gt; = {</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span 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) -&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"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">}</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px"><br></span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">print( (g) )</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">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"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px"><br></span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">print( (g.aFunc) )</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><font face="Menlo"><span style="font-size:12px">repl.swift:48:9: error: value of type &#39;Gen&lt;Int, (Int, Int), Int, (Int, Int)&gt;&#39; has no member &#39;aFunc&#39;</span></font></div></div><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><span style="font-size:12px;font-family:Menlo">        ^ ~~~~~</span></div></div></blockquote><div style="margin:0px;line-height:normal"><div style="margin:0px;line-height:normal"><br></div><div 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 style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Thanks.</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">Doug</div></div></div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">-Saagar Jha</div></div>