4 ms·
Nice, but I was hoping for something like: slice :: Int{1..} -> [a] -> [[a]] slice n l = splitAt n l & \(a, b) -> a : slice n b I don't think this is
by nemo1618 11y ago
Nice, but I was hoping for something like:
slice :: Int{1..} -> [a] -> [[a]]
slice n l =
splitAt n l & \(a, b) -> a : slice n b
I don't think this is possible in Haskell. Is there a language that supports this sort of syntax?
(Also, what's up with that &? It doesn't seem to be a Prelude operator.)
- ics 11y agoRegarding &: https://www.fpcomplete.com/hoogle?q=%26&env=ghc-7.8-stable-14.09 https://www.fpcomplete.com/hoogle?q=%26&env=ghc-7.8-stable-1... If it's from lens, then it's "the flipped version of ($)".
- mijoharas 11y agoThere is a similar explanation if you search google for `haskell ampersand`[0] [0] http://qerub.se/ampersand http://qerub.se/ampersand
- CMCDragonkai 11y agoWhat's the difference (&) and reverse function composition?
- dllthomas 11y agoPrecisely the difference between function application and function composition.
- typish 11y agoLiquid Haskell might be what you are looking for: http://goto.ucsd.edu/~rjhala/papers/real_world_liquid.pdf http://goto.ucsd.edu/~rjhala/papers/real_world_liquid.pdf An example from that paper: type Nat = {v:Int | 0 <=v } type Pos = {v:Int | 0 < v } div :: Nat -> d:Pos -> {v:Nat | v <= n} The ATS programming language (http://www.ats-lang.org http://www.ats-lang.org) is more ML-like than Haskell-like but can have ranged integer types. Something like: fun slice {n:int | n >= 1} (a:int n, b:list)
- seanwilson 11y agoDependently typed languages like DML, Epigram, ATS, Coq, Agda or Idris supports these kind of types. Unfortunately it quickly becomes difficult to work with this kind of typing when you introduce more complex properties.
- nikita-volkov 11y ago> Also, what's up with that &? It doesn't seem to be a Prelude operator. It's now in [Data.Function of "base"](http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Function.html#v:-38- http://hackage.haskell.org/package/base-4.8.0.0/docs/Data-Fu...) and hence in ["base-prelude"](http://hackage.haskell.org/package/base-prelude http://hackage.haskell.org/package/base-prelude).