scala - Type inference question using Scalaz.ListW.<^> -


I was playing around, its definition is as follows:

  def & lt; ^ & Gt; [B: Zero] (F: Noneptist [A] = & gt; B): B = value Match {Case Neal = & gt; ∅ Case H: T = & gt; F. (Scalaz.nel (h, t))}  

I do not know how to select option as zero Type this example for

  scala> Case class CC (V: int) defined square cc scale & gt; List [CC] = List (CC (2), CC (5), CC (1))  

Pre>

So now I have a list of these things. The goal is to get the option [CC] for at least Poisson , where I get any none if none is zero Less than and equal to max.

  scala & gt; Import scalaz._; Import Scalaz._ Import scalaz._ Import Scalaz._ scala & gt; Built-in valid ccdor = new order [cc] {| Def order (v1: cc, v2: cc) = order by ((v: cc) => v.v) .order (v1, v2) | } CCOD: java.lang.Object scalaz.Order [CC] = $ anon $ 1 @ 1e48d65 scale & gt; Posns.filter (_. V <0) & lt; ^ & Gt; (_.min) res0: option [cc] = any mark & ​​gt; Posns.filter (_ v & gt; 0) & lt; ^ & Gt; (_.max) res1: option [cc] = some (cc (5))  

option exactly zero type I Wanted! Can anyone explain that how does option choose?

ListW # & lt; ^ & Gt; Sealed specialty MA [M], A] Pumpi type [M [A order [A] = option and MA # min :

A] = fold 1 ((X: A, Y: A) => if (x ≨ y) x and y): b = value match {case nil => gt;} [b] zero: (f) : Non Active List [A] => B); ∅ Case H: T = & gt; F (Scalaz.nel (h, t))}}

Here are the relevant approximation types, built-in conversions, and the underlying parameters. Scalac -Xprint: typer will reveal this.

  object test {import scalaz._ import Scalaz._ case class CC (v: int) val posns = List cc (2), cc (5), cc (1) val filter Done = posns.filter ((x $ 1: cc) => x $ 1.v. & lt; (0)) val listw = Scalaz.ListTo [CC] (posns.filter ((x $ 1: cc) = & gt; x $ 1.v. & lt; (0)))) List & Lt; ^ & Gt; [Option [cc]] {(x $ 2: scales .NonEmptyList [CC]) => Scalaz.maImplicit [scalaz.NonEmptyList, CC] (x $ 2) .min (Foldable.NonEmptyListFoldable, CCOrder)} (Zero OptionJarrow [CC]); }  

list @ # & lt; ^ & Gt; missing list [A] = & gt; B If the pimped list is non-empty, otherwise returns returns for zero type B . MA # Minutes Really Returns Option [B] - This is a common task for containers, not specific to NonEmptyList , where it It is possible to return a b .

Another direct way to get this is to call MA # min directly. Unfortunately, in the list already there is a minimum function, which is new to Scala 2.8, therefore the view contained in the code for MA is a type sign Has not been triggered without:

  posns.filter (_ v. And lt; 0) .min & lt; Console & gt ;: 16: Error: The value for the parameter cmp could not be found: [CC] posns.filter [_ V & lt; 0) .min (posns.filter (_ v. Lt; 0): MA [list, cc]). Min res7: Option [CC] = Any  

This is one of the inspirational reasons for providing a symbolic identifier in Scalaz - this is a raw form of name-space!

Order [cc] = orderbase (_. V) ccoder: scales. Order [cc] = scales Order: $$ anon $ 2 @ fc2528


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -