Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/vis15/src/compiler/mlton/list.sml
ViewVC logotype

View of /branches/vis15/src/compiler/mlton/list.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3863 - (download) (annotate)
Sun May 15 17:18:04 2016 UTC (3 years ago) by jhr
File size: 873 byte(s)
  working on merge
(* list.sml
 *
 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
 *
 * COPYRIGHT (c) 2016 The University of Chicago
 * All rights reserved.
 *)

signature LIST_EXT =
  sig

    include LIST

    val appi : (int * 'a -> unit) -> 'a list -> unit
    val mapi : (int * 'a -> 'b) -> 'a list -> 'b list

    val revMap : ('a -> 'b) -> 'a list -> 'b list

  end

structure ListExt : LIST_EXT =
  struct

    open List

    fun appi f xs = let
	  fun appf ([], _) = ()
	    | appf (x::xs, i) = (f (i, x); appf (xs, i+1))
	  in
	    appf (xs, 0)
	  end

    fun mapi f xs = let
	  fun mapf ([], _, ys) = List.rev ys
	    | mapf (x::xs, i, ys) = mapf (xs, i+1, f(i, x)::ys)
	  in
	    mapf (xs, 0, [])
	  end

    fun revMap f l = let
	  fun mapf (x::xs, ys) = mapf (xs, f x :: ys)
	    | mapf ([], ys) = ys
	  in
	    mapf (l, [])
	  end

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0