Commit 4836f16 1 parent e721480 commit 4836f16 Copy full SHA for 4836f16
File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ package BuildList where
2
+
3
+ import List
4
+
5
+ -- A typeclass used to implement a vector construction function which can take
6
+ -- any number of arguments (>0).
7
+ -- The type parameter `a` is the type of the elements in the list.
8
+ -- The type parameter `r` is the return type of the function, which can be a
9
+ -- list (base case) or a function (recursive case) that takes another element
10
+ -- and returns a new function.
11
+ -- The list here is built in reverse for efficiency, and then reversed.
12
+ class BuildList a r | r -> a where
13
+ lst' :: List a -> a -> r
14
+
15
+ instance BuildList a (List a ) where
16
+ lst' l x = reverse $ x : > l
17
+
18
+ instance (BuildList a r ) => BuildList a (a -> r ) where
19
+ lst' l x y = lst' (x : > l) y
20
+
21
+ -- Example usage:
22
+ -- lst 1 2 3 4 5 => 1 :> 2 :> 3 :> 4 :> 5 :> nil
23
+ -- lst False => False :> nil
24
+ lst :: (BuildList a r ) => a -> r
25
+ lst x = lst' nil x
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package Misc;
3
3
import Arbiter :: * ;
4
4
import BRAM :: * ;
5
5
import BRAMFIFO :: * ;
6
+ import BuildList :: * ;
6
7
import BuildVector :: * ;
7
8
import BUtils :: * ;
8
9
import BypassReg :: * ;
You can’t perform that action at this time.
0 commit comments