× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Haskell-style type families

Carsten König
Jul 17, 2015
<p>I have no clue if you will ever find a use for this, but I think the obvious translation should be</p> <pre><code>class ListLike k where llElem : Type fromList : List llElem -&gt; k instance ListLike (List a) where llElem = a fromList = id instance ListLike (Maybe a) where llElem = a fromList [] = Nothing fromList (a::_) = Just a </code></pre> <h3>usage</h3> <pre><code>λΠ&gt; the (Maybe Int) (fromList [3]) Just 3 : Maybe Int λΠ&gt; the (List Int) (fromList [3]) [3] : List Int </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/30619750/Haskell-style%20type%20families/30623992">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus