Functional operators in Nemerle
От: Liviu1  
Дата: 23.03.14 22:21
Оценка:
Hi all,

Are there builint operators in Nemerle like |> >> << <| from F#.
They can be built with macros but I like experience.
For example:

macro @|> (e1, e2)
  {
    <[ $e2($e1) ]>
  }


I write:

 "a" |> Console.WriteLine


What precedence value should i specify in operator attribute?

How to implement <| which is right associative?

Thanks
nemerle
Re: Functional operators in Nemerle
От: Don Reba Канада https://stackoverflow.com/users/49329/don-reba
Дата: 23.03.14 22:40
Оценка: 3 (1)
You don't even need a macro. |> is already a function in the standard library, defined like this:

public static @|> (a : 'p1, fac : 'p1 -> 'r) : 'r
{
    fac(a)
}
public static @|> (a : 'p1, fac : 'p1 -> void) : void
{
    fac(a)
}


There are also <<, >>, and <|. You can find them all in lib/internal-numbered.n.
Ce n'est que pour vous dire ce que je vous dis.
Re[2]: Functional operators in Nemerle
От: Liviu1  
Дата: 23.03.14 22:44
Оценка:
Здравствуйте, Don Reba, Вы писали:

DR>You don't even need a macro. |> is already a function in the standard library, defined like this:


DR>
DR>public static @|> (a : 'p1, fac : 'p1 -> 'r) : 'r
DR>{
DR>    fac(a)
DR>}
DR>public static @|> (a : 'p1, fac : 'p1 -> void) : void
DR>{
DR>    fac(a)
DR>}
DR>


DR>There are also <<, >>, and <|. You can find them all in lib/internal-numbered.n.



Thank you!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.